ZQuest Classic Coverage Report


Directory: src/
File: src/zc/zc_sys.cpp
Date: 2025-05-30 08:30:52
Exec Total Coverage
Lines: 2012 4564 44.1%
Functions: 142 337 42.1%
Branches: 1340 3758 35.7%

Line Branch Exec Source
1 #include "zc/zc_sys.h"
2
3 #include "allegro/gfx.h"
4 #include "allegro/gui.h"
5 #include "allegro/inline/draw.inl"
6 #include "allegro5/joystick.h"
7 #include "base/files.h"
8 #include "base/render.h"
9 #include "base/zdefs.h"
10 #include "zalleg/zalleg.h"
11 #include "base/qrs.h"
12 #include "base/dmap.h"
13 #include <functional>
14 #include <queue>
15 #include <stdio.h>
16 #include <stdlib.h>
17 #include <cstring>
18 #include <math.h>
19 #include <map>
20 #include <filesystem>
21 #include <ctype.h>
22 #include <sstream>
23 #include "base/version.h"
24 #include "base/zc_alleg.h"
25 #include "gamedata.h"
26 #include "zc/replay_upload.h"
27 #include "zc/zc_init.h"
28 #include "init.h"
29 #include "zc/replay.h"
30 #include "zc/cheats.h"
31 #include "zc/render.h"
32 #include "base/zc_math.h"
33 #include "base/zapp.h"
34 #include "dialog/cheatkeys.h"
35 #include "metadata/metadata.h"
36 #include "zc/zelda.h"
37 #include "zc/saves.h"
38 #include "tiles.h"
39 #include "base/colors.h"
40 #include "pal.h"
41 #include "base/zsys.h"
42 #include "base/qst.h"
43 #include "zc/zc_sys.h"
44 #include "play_midi.h"
45 #include "gui/jwin_a5.h"
46 #include "base/jwinfsel.h"
47 #include "base/gui.h"
48 #include "midi.h"
49 #include "subscr.h"
50 #include "zc/maps.h"
51 #include "sprite.h"
52 #include "zc/guys.h"
53 #include "zc/hero.h"
54 #include "zc/title.h"
55 #include "particles.h"
56 #include "sound/zcmusic.h"
57 #include "zc/ffscript.h"
58 #include "dialog/info.h"
59 #include "dialog/alert.h"
60 #include "zc/combos.h"
61 #include "zc/jit.h"
62 #include "zc/zc_subscr.h"
63 #include <fmt/format.h>
64 #include "zconsole/ConsoleLogger.h"
65 #include "zinfo.h"
66 #include "base/misctypes.h"
67 #include "music_playback.h"
68 #include "base/new_menu.h"
69 #include "base/files.h"
70 #include "iter.h"
71
72 #ifdef __EMSCRIPTEN__
73 #include "base/emscripten_utils.h"
74 #endif
75
76 using namespace std::chrono_literals;
77
78 extern bool Playing;
79 int32_t sfx_voice[WAV_COUNT];
80 int32_t d_stringloader(int32_t msg,DIALOG *d,int32_t c);
81 int32_t d_midilist_proc(int32_t msg,DIALOG *d,int32_t c);
82
83 static ALLEGRO_JOYSTICK* gamepad_dlg_cur_joystick;
84 static int32_t d_joylist_proc(int32_t msg,DIALOG *d,int32_t c);
85
86 extern byte monochrome_console;
87
88 extern sprite_list guys, items, Ewpns, Lwpns, chainlinks, decorations;
89 extern int32_t loadlast;
90 extern char *sfx_string[WAV_COUNT];
91 byte use_dwm_flush;
92 byte use_save_indicator;
93 int32_t paused_midi_pos = 0;
94 byte midi_suspended = 0;
95 byte zc_192b163_warp_compatibility;
96 bool epilepsyFlashReduction;
97 signed char pause_in_background_menu_init = 0;
98 byte pause_in_background = 0;
99 bool is_sys_pal = false;
100 static bool load_control_called_this_frame;
101 extern PALETTE* hw_palette;
102 extern bool update_hw_pal;
103 extern const char* dmaplist(int32_t index, int32_t* list_size);
104 int32_t getnumber(const char *prompt,int32_t initialval);
105
106 extern bool kb_typing_mode; //script only, for disbaling key presses affecting Hero, etc.
107 extern int32_t cheat_modifier_keys[4]; //two options each, default either control and either shift
108
109 #ifdef ALLEGRO_LINUX
110 static const char *samplepath = "samplesoundset/patches.dat";
111 #endif
112 char qst_files_path[2048];
113
114 extern TopMenu the_player_menu;
115 #ifdef _MSC_VER
116 #define getcwd _getcwd
117 #endif
118
119 bool rF11();
120 bool rI();
121 bool rQ();
122 bool zc_key_pressed();
123
124 #ifdef _WIN32
125
126 // This should only be necessary for MinGW, since it doesn't have a dwmapi.h. Add another #ifdef if you like.
127 extern "C"
128 {
129 typedef HRESULT(WINAPI *t_DwmFlush)();
130 typedef HRESULT(WINAPI *t_DwmIsCompositionEnabled)(BOOL *pfEnabled);
131 }
132
133 void do_DwmFlush()
134 {
135 static HMODULE shell = LoadLibrary("dwmapi.dll");
136
137 if(!shell)
138 return;
139
140 static t_DwmFlush flush=reinterpret_cast<t_DwmFlush>(GetProcAddress(shell, "DwmFlush"));
141 static t_DwmIsCompositionEnabled isEnabled=reinterpret_cast<t_DwmIsCompositionEnabled>(GetProcAddress(shell, "DwmIsCompositionEnabled"));
142
143 BOOL enabled;
144 isEnabled(&enabled);
145
146 if(isEnabled)
147 flush();
148 }
149
150 #endif // _WIN32
151
152 308 void zc_exit(int code)
153 {
154 extern CConsoleLoggerEx zscript_coloured_console;
155
156 308 set_is_exiting();
157
158
1/2
✓ Branch 0 taken 308 times.
✗ Branch 1 not taken.
308 if (replay_get_mode() == ReplayMode::Record) replay_save();
159 308 replay_stop();
160 308 music_stop();
161 308 kill_sfx();
162
163
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 301 times.
308 if (get_qr(qr_OLD_SCRIPT_VOLUME))
164 {
165 //restore user volume settings
166
2/2
✓ Branch 0 taken 300 times.
✓ Branch 1 taken 1 times.
301 if (FFCore.coreflags & FFCORE_SCRIPTED_MIDI_VOLUME)
167 {
168 1 master_volume(-1, ((int32_t)FFCore.usr_midi_volume));
169 1 }
170
2/2
✓ Branch 0 taken 300 times.
✓ Branch 1 taken 1 times.
301 if (FFCore.coreflags & FFCORE_SCRIPTED_DIGI_VOLUME)
171 {
172 1 master_volume((int32_t)(FFCore.usr_digi_volume), 1);
173 1 }
174
2/2
✓ Branch 0 taken 300 times.
✓ Branch 1 taken 1 times.
301 if (FFCore.coreflags & FFCORE_SCRIPTED_MUSIC_VOLUME)
175 {
176 1 emusic_volume = (int32_t)FFCore.usr_music_volume;
177 1 }
178
1/2
✓ Branch 0 taken 301 times.
✗ Branch 1 not taken.
301 if (FFCore.coreflags & FFCORE_SCRIPTED_SFX_VOLUME)
179 {
180 sfx_volume = (int32_t)FFCore.usr_sfx_volume;
181 }
182 301 }
183
1/2
✓ Branch 0 taken 308 times.
✗ Branch 1 not taken.
308 if ( FFCore.coreflags&FFCORE_SCRIPTED_PANSTYLE )
184 {
185 pan_style = (int32_t)FFCore.usr_panstyle;
186 }
187 308 save_game_configs();
188
189 308 zscript_coloured_console.kill();
190 308 jit_shutdown();
191 308 quit_game();
192
193 308 Z_message("ZQuest Classic website: https://zquestclassic.com\n");
194 308 Z_message("ZQuest Classic docs: https://docs.zquestclassic.com\n");
195
196 308 allegro_exit();
197 308 exit(code);
198 }
199
200 92877 bool flash_reduction_enabled(bool check_qr)
201 {
202
4/4
✓ Branch 0 taken 88452 times.
✓ Branch 1 taken 4425 times.
✓ Branch 2 taken 87624 times.
✓ Branch 3 taken 92049 times.
92877 return (check_qr && get_qr(qr_EPILEPSY)) || epilepsyFlashReduction || replay_is_debug();
203 }
204
205 // Dialogue largening
206 void large_dialog(DIALOG *d)
207 {
208 large_dialog(d, 1.5);
209 }
210
211 void large_dialog(DIALOG *d, float RESIZE_AMT)
212 {
213 if(!d[0].d1)
214 {
215 d[0].d1 = 1;
216 int32_t oldwidth = d[0].w;
217 int32_t oldheight = d[0].h;
218 int32_t oldx = d[0].x;
219 int32_t oldy = d[0].y;
220 d[0].x -= int32_t(d[0].w/RESIZE_AMT);
221 d[0].y -= int32_t(d[0].h/RESIZE_AMT);
222 d[0].w = int32_t(d[0].w*RESIZE_AMT);
223 d[0].h = int32_t(d[0].h*RESIZE_AMT);
224
225 for(int32_t i=1; d[i].proc !=NULL; i++)
226 {
227 // Place elements horizontally
228 double xpc = ((double)(d[i].x - oldx) / (double)oldwidth);
229 d[i].x = int32_t(d[0].x + (xpc*d[0].w));
230
231 if(d[i].proc != d_stringloader)
232 {
233 if(d[i].proc==d_bitmap_proc)
234 {
235 d[i].w *= 2;
236 }
237 else d[i].w = int32_t(d[i].w*RESIZE_AMT);
238 }
239
240 // Place elements vertically
241 double ypc = ((double)(d[i].y - oldy) / (double)oldheight);
242 d[i].y = int32_t(d[0].y + (ypc*d[0].h));
243
244 // Vertically resize elements
245 if(d[i].proc == jwin_edit_proc || d[i].proc == jwin_check_proc || d[i].proc == jwin_checkfont_proc)
246 {
247 d[i].h = int32_t((double)d[i].h*1.5);
248 }
249 else if(d[i].proc == jwin_droplist_proc || d[i].proc == d_joylist_proc)
250 {
251 d[i].y += int32_t((double)d[i].h*0.25);
252 d[i].h = int32_t((double)d[i].h*1.25);
253 }
254 else if(d[i].proc==d_bitmap_proc)
255 {
256 d[i].h *= 2;
257 }
258 else d[i].h = int32_t(d[i].h*RESIZE_AMT);
259
260 // Fix frames
261 if(d[i].proc == jwin_frame_proc)
262 {
263 d[i].x++;
264 d[i].y++;
265 d[i].w-=4;
266 d[i].h-=4;
267 }
268 }
269 }
270
271 for(int32_t i=1; d[i].proc!=NULL; i++)
272 {
273 if(d[i].proc==jwin_slider_proc)
274 continue;
275
276 // Bigger font
277 bool bigfontproc = (d[i].proc != d_midilist_proc && d[i].proc != jwin_droplist_proc && d[i].proc != jwin_abclist_proc && d[i].proc != jwin_list_proc && d[i].proc != d_joylist_proc);
278
279 if(!d[i].dp2 && bigfontproc)
280 {
281 d[i].dp2 = get_zc_font(font_lfont_l);
282 }
283 else if(!bigfontproc)
284 {
285 ((ListData *)d[i].dp)->font = &a4fonts[font_lfont_l];
286 }
287
288 // Make checkboxes work
289 if(d[i].proc == jwin_check_proc)
290 d[i].proc = jwin_checkfont_proc;
291 else if(d[i].proc == jwin_radio_proc)
292 d[i].proc = jwin_radiofont_proc;
293 }
294
295 jwin_center_dialog(d);
296 }
297
298 static char cfg_sect[] = "zeldadx"; //We need to rename this.
299 static char ctrl_sect[] = "Controls";
300 static char sfx_sect[] = "Volume";
301
302 int32_t d_dummy_proc(int32_t,DIALOG *,int32_t)
303 {
304 return D_O_K;
305 }
306
307 bool is_reserved_key(int c)
308 {
309 switch(c)
310 {
311 case KEY_ESC:
312 return true;
313 }
314 return false;
315 }
316 bool is_reserved_keycombo(int c, int modflag)
317 {
318 if(c==KEY_F4 && (modflag&KB_ALT_FLAG))
319 return true;
320 return false;
321 }
322 bool checkcheat(Cheat cheat)
323 {
324 if(cheatkeys[cheat][0] && zc_readkey(cheatkeys[cheat][0]))
325 return true; //Main key pressed
326 if(cheatkeys[cheat][1] && zc_readkey(cheatkeys[cheat][1]))
327 return true; //Alt key pressed
328 return false;
329 }
330 308 void load_default_cheatkeys()
331 {
332 308 memset(cheatkeys, 0, sizeof(cheatkeys));
333 308 cheatkeys[Cheat::Life][0] = KEY_H;
334 308 cheatkeys[Cheat::Life][1] = KEY_ASTERISK;
335 308 cheatkeys[Cheat::Magic][0] = KEY_M;
336 308 cheatkeys[Cheat::Magic][1] = KEY_SLASH_PAD;
337 308 cheatkeys[Cheat::Rupies][0] = KEY_R;
338 308 cheatkeys[Cheat::Bombs][0] = KEY_B;
339 308 cheatkeys[Cheat::Arrows][0] = KEY_A;
340 308 cheatkeys[Cheat::Clock][0] = KEY_I;
341 308 cheatkeys[Cheat::Walls][0] = KEY_F11;
342 308 cheatkeys[Cheat::Fast][0] = KEY_Q;
343 308 cheatkeys[Cheat::Light][0] = KEY_L;
344 308 cheatkeys[Cheat::IgnoreSideView][0] = KEY_V;
345 308 cheatkeys[Cheat::Kill][0] = KEY_K;
346 308 cheatkeys[Cheat::GoTo][0] = KEY_G;
347 308 cheatkeys[Cheat::TrigSecrets][0] = KEY_S;
348 308 cheatkeys[Cheat::ShowL0][0] = KEY_0;
349 308 cheatkeys[Cheat::ShowL1][0] = KEY_1;
350 308 cheatkeys[Cheat::ShowL2][0] = KEY_2;
351 308 cheatkeys[Cheat::ShowL3][0] = KEY_3;
352 308 cheatkeys[Cheat::ShowL4][0] = KEY_4;
353 308 cheatkeys[Cheat::ShowL5][0] = KEY_5;
354 308 cheatkeys[Cheat::ShowL6][0] = KEY_6;
355 308 cheatkeys[Cheat::ShowFFC][0] = KEY_7;
356 308 cheatkeys[Cheat::ShowSprites][0] = KEY_8;
357 308 cheatkeys[Cheat::ShowWalkability][0] = KEY_W;
358 308 cheatkeys[Cheat::ShowEffects][0] = KEY_E;
359 308 cheatkeys[Cheat::ShowOverhead][0] = KEY_O;
360 308 cheatkeys[Cheat::ShowPushblock][0] = KEY_P;
361 308 cheatkeys[Cheat::ShowHitbox][0] = KEY_C;
362 308 cheatkeys[Cheat::ShowFFCScripts][0] = KEY_F;
363 308 }
364
365 static bool loaded_game_configs;
366
367 308 void load_game_configs()
368 {
369 308 loaded_game_configs = true;
370 308 joystick_index = zc_get_config(ctrl_sect,"joystick_index",0);
371 308 js_stick_1_x_stick = zc_get_config(ctrl_sect,"js_stick_1_x_stick",0);
372 308 js_stick_1_x_axis = zc_get_config(ctrl_sect,"js_stick_1_x_axis",0);
373 308 js_stick_1_x_offset = zc_get_config(ctrl_sect,"js_stick_1_x_offset",0) ? 128 : 0;
374 308 js_stick_1_y_stick = zc_get_config(ctrl_sect,"js_stick_1_y_stick",0);
375 308 js_stick_1_y_axis = zc_get_config(ctrl_sect,"js_stick_1_y_axis",1);
376 308 js_stick_1_y_offset = zc_get_config(ctrl_sect,"js_stick_1_y_offset",0) ? 128 : 0;
377 308 js_stick_2_x_stick = zc_get_config(ctrl_sect,"js_stick_2_x_stick",1);
378 308 js_stick_2_x_axis = zc_get_config(ctrl_sect,"js_stick_2_x_axis",0);
379 308 js_stick_2_x_offset = zc_get_config(ctrl_sect,"js_stick_2_x_offset",0) ? 128 : 0;
380 308 js_stick_2_y_stick = zc_get_config(ctrl_sect,"js_stick_2_y_stick",1);
381 308 js_stick_2_y_axis = zc_get_config(ctrl_sect,"js_stick_2_y_axis",1);
382 308 js_stick_2_y_offset = zc_get_config(ctrl_sect,"js_stick_2_y_offset",0) ? 128 : 0;
383 308 analog_movement = (zc_get_config(ctrl_sect,"analog_movement",1));
384
385 //cheat modifier keya
386 308 cheat_modifier_keys[0] = zc_get_config(ctrl_sect,"key_cheatmod_a1",KEY_ZC_LCONTROL);
387 308 cheat_modifier_keys[1] = zc_get_config(ctrl_sect,"key_cheatmod_a2",0);
388 308 cheat_modifier_keys[2] = zc_get_config(ctrl_sect,"key_cheatmod_b1",KEY_ZC_RCONTROL);
389 308 cheat_modifier_keys[3] = zc_get_config(ctrl_sect,"key_cheatmod_b2",0);
390
391 //cheat keys
392 308 load_default_cheatkeys();
393 char buf[256];
394
2/2
✓ Branch 0 taken 308 times.
✓ Branch 1 taken 11088 times.
11396 for(size_t q = 1; q < Cheat::Last; ++q)
395 {
396
1/2
✓ Branch 0 taken 11088 times.
✗ Branch 1 not taken.
11088 if(!bindable_cheat((Cheat)q)) continue;
397 11088 std::string cheatname = cheat_to_string((Cheat)q);
398
1/2
✓ Branch 0 taken 11088 times.
✗ Branch 1 not taken.
11088 util::lowerstr(cheatname);
399 11088 sprintf(buf, "key_cheat_%s_main", cheatname.c_str());
400
1/2
✓ Branch 0 taken 11088 times.
✗ Branch 1 not taken.
11088 cheatkeys[q][0] = zc_get_config(ctrl_sect,buf,cheatkeys[q][0]);
401 11088 sprintf(buf, "key_cheat_%s_alt", cheatname.c_str());
402
1/2
✓ Branch 0 taken 11088 times.
✗ Branch 1 not taken.
11088 cheatkeys[q][1] = zc_get_config(ctrl_sect,buf,cheatkeys[q][1]);
403 11088 }
404
405
1/2
✓ Branch 0 taken 308 times.
✗ Branch 1 not taken.
308 if((uint32_t)joystick_index >= MAX_JOYSTICKS)
406 joystick_index = 0;
407
408 308 Akey = zc_get_config(ctrl_sect,"key_a",KEY_Z);
409 308 Bkey = zc_get_config(ctrl_sect,"key_b",KEY_X);
410 308 Skey = zc_get_config(ctrl_sect,"key_s",KEY_ENTER);
411 308 Lkey = zc_get_config(ctrl_sect,"key_l",KEY_Q);
412 308 Rkey = zc_get_config(ctrl_sect,"key_r",KEY_W);
413 308 Pkey = zc_get_config(ctrl_sect,"key_p",KEY_SPACE);
414 308 Exkey1 = zc_get_config(ctrl_sect,"key_ex1",KEY_A);
415 308 Exkey2 = zc_get_config(ctrl_sect,"key_ex2",KEY_S);
416 308 Exkey3 = zc_get_config(ctrl_sect,"key_ex3",KEY_D);
417 308 Exkey4 = zc_get_config(ctrl_sect,"key_ex4",KEY_C);
418
419 308 DUkey = zc_get_config(ctrl_sect,"key_up", KEY_UP);
420 308 DDkey = zc_get_config(ctrl_sect,"key_down", KEY_DOWN);
421 308 DLkey = zc_get_config(ctrl_sect,"key_left", KEY_LEFT);
422 308 DRkey = zc_get_config(ctrl_sect,"key_right",KEY_RIGHT);
423
424 308 Abtn = zc_get_config(ctrl_sect,"btn_a",2);
425 308 Bbtn = zc_get_config(ctrl_sect,"btn_b",1);
426 308 Sbtn = zc_get_config(ctrl_sect,"btn_s",10);
427 308 Mbtn = zc_get_config(ctrl_sect,"btn_m",9);
428 308 Lbtn = zc_get_config(ctrl_sect,"btn_l",5);
429 308 Rbtn = zc_get_config(ctrl_sect,"btn_r",6);
430 308 Pbtn = zc_get_config(ctrl_sect,"btn_p",12);
431 308 Exbtn1 = zc_get_config(ctrl_sect,"btn_ex1",7);
432 308 Exbtn2 = zc_get_config(ctrl_sect,"btn_ex2",8);
433 308 Exbtn3 = zc_get_config(ctrl_sect,"btn_ex3",4);
434 308 Exbtn4 = zc_get_config(ctrl_sect,"btn_ex4",3);
435
436 308 DUbtn = zc_get_config(ctrl_sect,"btn_up",13);
437 308 DDbtn = zc_get_config(ctrl_sect,"btn_down",14);
438 308 DLbtn = zc_get_config(ctrl_sect,"btn_left",15);
439 308 DRbtn = zc_get_config(ctrl_sect,"btn_right",16);
440
441 308 epilepsyFlashReduction = zc_get_config(cfg_sect,"epilepsy_flash_reduction",0);
442
443 308 midi_volume = zc_get_config(sfx_sect,"midi",255);
444 308 sfx_volume = zc_get_config(sfx_sect,"sfx",255);
445 308 emusic_volume = zc_get_config(sfx_sect,"emusic",255);
446 308 pan_style = zc_get_config(sfx_sect,"pan",1);
447 308 volkeys = zc_get_config(sfx_sect,"volkeys",0)!=0;
448 308 zc_vsync = zc_get_config(cfg_sect,"vsync",0);
449 308 Throttlefps = zc_get_config(cfg_sect,"throttlefps",1)!=0;
450 308 Maxfps = zc_get_config(cfg_sect,"maxfps",0);
451 308 TransLayers = zc_get_config(cfg_sect,"translayers",1)!=0;
452 308 SnapshotFormat = zc_get_config(cfg_sect,"snapshot_format",3);
453 308 ShowBottomPixels = zc_get_config(cfg_sect,"bottom_8_px",0);
454 308 SnapshotScale = zc_get_config(cfg_sect,"snapshot_scale",2);
455 308 NameEntryMode = zc_get_config(cfg_sect,"name_entry_mode",0);
456 #ifdef __EMSCRIPTEN__
457 if (em_is_mobile()) NameEntryMode = 2;
458 #endif
459 308 ShowFPS = zc_get_config(cfg_sect,"showfps",0)!=0;
460 308 ShowGameTime = zc_get_config(cfg_sect,"showtime",0);
461 308 NESquit = zc_get_config(cfg_sect,"fastquit",0)!=0;
462 308 ClickToFreeze = zc_get_config(cfg_sect,"clicktofreeze",1)!=0;
463 308 abc_patternmatch = zc_get_config(cfg_sect, "lister_pattern_matching", 1);
464 308 pause_in_background = zc_get_config(cfg_sect, "pause_in_background", 0);
465
466 308 window_width = resx = zc_get_config(cfg_sect,"window_width",-1);
467 308 window_height = resy = zc_get_config(cfg_sect,"window_height",-1);
468 308 SaveDragResize = zc_get_config(cfg_sect,"save_drag_resize",0)!=0;
469 308 DragAspect = zc_get_config(cfg_sect,"drag_aspect",0)!=0;
470 308 SaveWinPos = zc_get_config(cfg_sect,"save_window_position",0)!=0;
471 308 scaleForceInteger = zc_get_config("zeldadx","scaling_force_integer",1)!=0;
472 308 stretchGame = zc_get_config("zeldadx","stretch_game_area",0)!=0;
473
474 308 loadlast = zc_get_config(cfg_sect,"load_last",0);
475
476 308 fullscreen = zc_get_config(cfg_sect,"fullscreen",0);
477
478 308 info_opacity = zc_get_config("zc","debug_info_opacity",255);
479 #ifdef _WIN32
480 console_enabled = (byte) zc_get_config("CONSOLE", "enabled", 0);
481 //use_win7_keyboard_fix = (byte) zc_get_config(cfg_sect,"use_win7_key_fix",0);
482 use_win32_proc = (byte) zc_get_config(cfg_sect,"zc_win_proc_fix",0); //buggy
483
484 // This one's for Aero
485 use_dwm_flush = (byte) zc_get_config("zeldadx","use_dwm_flush",0);
486
487 monochrome_console = (byte) zc_get_config("CONSOLE","monochrome_debuggers",0);
488 #else //UNIX
489 308 console_enabled = (byte) zc_get_config("CONSOLE", "enabled", 0);
490 308 monochrome_console = (byte) zc_get_config("CONSOLE","monochrome_debuggers",0);
491 #endif
492 308 clearConsoleOnLoad = zc_get_config("CONSOLE","clear_console_on_load",1)!=0;
493 308 clearConsoleOnReload = zc_get_config("CONSOLE","clear_console_on_reload",0)!=0;
494
495 308 strcpy(qstdir,zc_get_config(cfg_sect,"quest_dir","quests"));
496 308 strcpy(qstpath,qstdir); //qstpath is the local (for this run of ZC) quest path, qstdir is the universal quest dir.
497 308 ss_enable = zc_get_config(cfg_sect,"ss_enable",1) ? 1 : 0;
498 308 ss_after = vbound(zc_get_config(cfg_sect,"ss_after",14), 0, 14);
499 308 ss_speed = vbound(zc_get_config(cfg_sect,"ss_speed",2), 0, 6);
500 308 ss_density = vbound(zc_get_config(cfg_sect,"ss_density",3), 0, 6);
501 308 heart_beep = zc_get_config(cfg_sect,"heart_beep",0)!=0;
502 //gui_colorset = zc_get_config(cfg_sect,"gui_colorset",0);
503 308 sfxdat = zc_get_config(cfg_sect,"use_sfx_dat",1); // TODO: sfxdat is always set to 1 for titlescreen... and 0 in readsfx... so this cfg is pointless, remove?
504 308 fullscreen = zc_get_config(cfg_sect,"fullscreen",0);
505 308 use_save_indicator = zc_get_config(cfg_sect,"save_indicator",0);
506 308 zc_192b163_warp_compatibility = zc_get_config(cfg_sect,"zc_192b163_warp_compatibility",0);
507 308 SkipTitle = zc_get_config(cfg_sect,"skip_title",0);
508 308 }
509
510 void save_control_configs(bool kb)
511 {
512 if(kb)
513 {
514 zc_set_config(ctrl_sect,"key_cheatmod_a1",cheat_modifier_keys[0]);
515 zc_set_config(ctrl_sect,"key_cheatmod_a2",cheat_modifier_keys[1]);
516 zc_set_config(ctrl_sect,"key_cheatmod_b1",cheat_modifier_keys[2]);
517 zc_set_config(ctrl_sect,"key_cheatmod_b2",cheat_modifier_keys[3]);
518
519 if (!replay_is_replaying())
520 {
521 zc_set_config(ctrl_sect,"key_a",Akey);
522 zc_set_config(ctrl_sect,"key_b",Bkey);
523 zc_set_config(ctrl_sect,"key_s",Skey);
524 zc_set_config(ctrl_sect,"key_l",Lkey);
525 zc_set_config(ctrl_sect,"key_r",Rkey);
526 zc_set_config(ctrl_sect,"key_p",Pkey);
527 zc_set_config(ctrl_sect,"key_ex1",Exkey1);
528 zc_set_config(ctrl_sect,"key_ex2",Exkey2);
529 zc_set_config(ctrl_sect,"key_ex3",Exkey3);
530 zc_set_config(ctrl_sect,"key_ex4",Exkey4);
531 zc_set_config(ctrl_sect,"key_up", DUkey);
532 zc_set_config(ctrl_sect,"key_down", DDkey);
533 zc_set_config(ctrl_sect,"key_left", DLkey);
534 zc_set_config(ctrl_sect,"key_right",DRkey);
535 }
536 }
537 else
538 {
539 zc_set_config(ctrl_sect,"joystick_index",joystick_index);
540 zc_set_config(ctrl_sect,"js_stick_1_x_stick",js_stick_1_x_stick);
541 zc_set_config(ctrl_sect,"js_stick_1_x_axis",js_stick_1_x_axis);
542 zc_set_config(ctrl_sect,"js_stick_1_x_offset",js_stick_1_x_offset ? 1 : 0);
543 zc_set_config(ctrl_sect,"js_stick_1_y_stick",js_stick_1_y_stick);
544 zc_set_config(ctrl_sect,"js_stick_1_y_axis",js_stick_1_y_axis);
545 zc_set_config(ctrl_sect,"js_stick_1_y_offset",js_stick_1_y_offset ? 1 : 0);
546 zc_set_config(ctrl_sect,"js_stick_2_x_stick",js_stick_2_x_stick);
547 zc_set_config(ctrl_sect,"js_stick_2_x_axis",js_stick_2_x_axis);
548 zc_set_config(ctrl_sect,"js_stick_2_x_offset",js_stick_2_x_offset ? 1 : 0);
549 zc_set_config(ctrl_sect,"js_stick_2_y_stick",js_stick_2_y_stick);
550 zc_set_config(ctrl_sect,"js_stick_2_y_axis",js_stick_2_y_axis);
551 zc_set_config(ctrl_sect,"js_stick_2_y_offset",js_stick_2_y_offset ? 1 : 0);
552 zc_set_config(ctrl_sect,"analog_movement",analog_movement);
553
554 zc_set_config(ctrl_sect,"btn_a",Abtn);
555 zc_set_config(ctrl_sect,"btn_b",Bbtn);
556 zc_set_config(ctrl_sect,"btn_s",Sbtn);
557 zc_set_config(ctrl_sect,"btn_m",Mbtn);
558 zc_set_config(ctrl_sect,"btn_l",Lbtn);
559 zc_set_config(ctrl_sect,"btn_r",Rbtn);
560 zc_set_config(ctrl_sect,"btn_p",Pbtn);
561 zc_set_config(ctrl_sect,"btn_ex1",Exbtn1);
562 zc_set_config(ctrl_sect,"btn_ex2",Exbtn2);
563 zc_set_config(ctrl_sect,"btn_ex3",Exbtn3);
564 zc_set_config(ctrl_sect,"btn_ex4",Exbtn4);
565
566 zc_set_config(ctrl_sect,"btn_up",DUbtn);
567 zc_set_config(ctrl_sect,"btn_down",DDbtn);
568 zc_set_config(ctrl_sect,"btn_left",DLbtn);
569 zc_set_config(ctrl_sect,"btn_right",DRbtn);
570 }
571 }
572
573 void save_cheatkeys()
574 {
575 char buf[256];
576 for(size_t q = 1; q < Cheat::Last; ++q)
577 {
578 if(!bindable_cheat((Cheat)q)) continue;
579 std::string cheatname = cheat_to_string((Cheat)q);
580 util::lowerstr(cheatname);
581 sprintf(buf, "key_cheat_%s_main", cheatname.c_str());
582 zc_set_config(ctrl_sect,buf,cheatkeys[q][0]);
583 sprintf(buf, "key_cheat_%s_alt", cheatname.c_str());
584 if(cheatkeys[q][1])
585 zc_set_config(ctrl_sect,buf,cheatkeys[q][1]);
586 else zc_set_config(ctrl_sect,buf,(char*)nullptr);
587 }
588 }
589
590 308 void save_game_configs()
591 {
592
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 308 times.
308 if (!loaded_game_configs) return;
593
594 308 packfile_password("");
595
596
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 308 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
308 if (all_get_display() && !all_get_fullscreen_flag()&& SaveWinPos)
597 {
598 int o_window_x, o_window_y;
599 al_get_window_position(all_get_display(), &o_window_x, &o_window_y);
600 zc_set_config(cfg_sect,"window_x",o_window_x);
601 zc_set_config(cfg_sect,"window_y",o_window_y);
602 }
603
604
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 308 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
308 if (all_get_display() && !all_get_fullscreen_flag() && SaveDragResize)
605 {
606 window_width = al_get_display_width(all_get_display());
607 window_height = al_get_display_height(all_get_display());
608 zc_set_config(cfg_sect,"window_width",window_width);
609 zc_set_config(cfg_sect,"window_height",window_height);
610 }
611
612 308 zc_set_config(cfg_sect,"load_last",loadlast);
613 308 zc_set_config(cfg_sect,"use_sfx_dat",sfxdat);
614
615 308 flush_config_file();
616 #ifdef __EMSCRIPTEN__
617 em_sync_fs();
618 #endif
619 308 }
620
621 //----------------------------------------------------------------
622
623 // Timers
624
625 39583 void fps_callback()
626 {
627 39583 lastfps=framecnt;
628 39583 framecnt=0;
629 39583 }
630
631 END_OF_FUNCTION(fps_callback)
632
633 308 int32_t Z_init_timers()
634 {
635 static bool didit = false;
636 const static char *err_str = "Couldn't allocate timer";
637 308 err_str = err_str; //Unused variable warning
638
639
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 308 times.
308 if(didit)
640 return 1;
641
642 308 didit = true;
643
644 LOCK_VARIABLE(lastfps);
645 LOCK_VARIABLE(framecnt);
646 LOCK_FUNCTION(fps_callback);
647
648
1/2
✓ Branch 0 taken 308 times.
✗ Branch 1 not taken.
308 if(install_int_ex(fps_callback,SECS_TO_TIMER(1)))
649 return 0;
650
651 308 return 1;
652 308 }
653
654 308 void Z_remove_timers()
655 {
656 308 remove_int(fps_callback);
657 308 }
658
659 //----------------------------------------------------------------
660
661 void go()
662 {
663 blit(screen,tmp_scr,scrx,scry,0,0,screen->w,screen->h);
664 }
665
666 void comeback()
667 {
668 blit(tmp_scr,screen,0,0,scrx,scry,screen->w,screen->h);
669 }
670
671 void dump_pal(BITMAP *dest)
672 {
673 for(int32_t i=0; i<256; i++)
674 rectfill(dest,(i&63)<<2,(i&0xFC0)>>4,((i&63)<<2)+3,((i&0xFC0)>>4)+3,i);
675 }
676
677 //----------------------------------------------------------------
678
679 int game_mouse_index = ZCM_BLANK;
680 static bool system_mouse = false;
681 90 bool sys_mouse()
682 {
683 90 system_mouse = true;
684 90 return MouseSprite::set(ZCM_NORMAL);
685 }
686 1585 bool game_mouse()
687 {
688 1585 system_mouse = false;
689 1585 return MouseSprite::set(game_mouse_index);
690 }
691 void custom_mouse(BITMAP* bmp, int fx, int fy, bool sys_recolor, bool user_scale)
692 {
693 if(!bmp)
694 return;
695 float scale = vbound(zc_get_config("zeldadx","cursor_scale_large",1.5),1.0,5.0);
696 int scaledw = bmp->w*scale, scaledh = bmp->h*scale;
697 if(bmp->w == scaledw && bmp->h == scaledh)
698 user_scale = false;
699 if(user_scale || sys_recolor)
700 {
701 if(!user_scale) scale = 1;
702 BITMAP* tmpbmp = create_bitmap_ex(8,bmp->w*scale,bmp->h*scale);
703 if(user_scale)
704 stretch_blit(bmp, tmpbmp, 0, 0, bmp->w, bmp->h, 0, 0, tmpbmp->w, tmpbmp->h);
705 else
706 blit(bmp, tmpbmp, 0, 0, 0, 0, bmp->w, bmp->h);
707 if(sys_recolor)
708 recolor_mouse(tmpbmp);
709 MouseSprite::assign(ZCM_CUSTOM, tmpbmp, fx*scale, fy*scale);
710 destroy_bitmap(tmpbmp);
711 }
712 else
713 {
714 MouseSprite::assign(ZCM_CUSTOM, bmp, fx, fy);
715 }
716 }
717
718 //Handles converting the mouse sprite from the .dat file
719 void recolor_mouse(BITMAP* bmp)
720 {
721 for(int32_t x = 0; x < bmp->w; ++x)
722 {
723 for(int32_t y = 0; y < bmp->h; ++y)
724 {
725 int32_t color = getpixel(bmp, x, y);
726 switch(color)
727 {
728 case dvc(1):
729 color = jwin_pal[jcCURSORMISC];
730 break;
731 case dvc(2):
732 color = jwin_pal[jcCURSOROUTLINE];
733 break;
734 case dvc(3):
735 color = jwin_pal[jcCURSORLIGHT];
736 break;
737 case dvc(5):
738 color = jwin_pal[jcCURSORDARK];
739 break;
740 default:
741 continue;
742 }
743 putpixel(bmp, x, y, color);
744 }
745 }
746 }
747 void load_mouse()
748 {
749 PALETTE pal;
750 BITMAP* cursor_bitmap = load_bitmap("assets/cursor.bmp", pal);
751 if (!cursor_bitmap)
752 Z_error_fatal("Missing required file %s\n", "assets/cursor.bmp");
753
754 enter_sys_pal();
755 MouseSprite::set(-1);
756 float scale = vbound(zc_get_config("zeldadx","cursor_scale_large",1.5),1.0,5.0);
757 int32_t sz = 16*scale;
758 for(int32_t j = 0; j < 1; ++j)
759 {
760 BITMAP* tmpbmp = create_bitmap_ex(8,16,16);
761 if(zcmouse[j])
762 destroy_bitmap(zcmouse[j]);
763 zcmouse[j] = create_bitmap_ex(8,sz,sz);
764 clear_bitmap(zcmouse[j]);
765 clear_bitmap(tmpbmp);
766 blit(cursor_bitmap,tmpbmp,1,j*17+1,0,0,16,16);
767 recolor_mouse(tmpbmp);
768 if(sz!=16)
769 stretch_blit(tmpbmp, zcmouse[j], 0, 0, 16, 16, 0, 0, sz, sz);
770 else
771 blit(tmpbmp, zcmouse[j], 0, 0, 0, 0, 16, 16);
772 destroy_bitmap(tmpbmp);
773 }
774 if(!hw_palette) hw_palette = &RAMpal;
775 zc_set_palette(*hw_palette);
776
777 BITMAP* blankmouse = create_bitmap_ex(8,16,16);
778 clear_bitmap(blankmouse);
779
780 MouseSprite::assign(ZCM_NORMAL, zcmouse[0], 1*scale, 1*scale);
781 MouseSprite::assign(ZCM_BLANK, blankmouse);
782 //Don't assign ZCM_CUSTOM. That'll be handled by scripts.
783
784 //Reload the mouse
785 if(system_mouse)
786 sys_mouse();
787 else game_mouse();
788
789 destroy_bitmap(blankmouse);
790 destroy_bitmap(cursor_bitmap);
791 exit_sys_pal();
792 }
793
794 // sets the video mode and initializes the palette and mouse sprite
795 308 bool game_vid_mode(int32_t mode,int32_t wait)
796 {
797
1/2
✓ Branch 0 taken 308 times.
✗ Branch 1 not taken.
308 if (is_headless())
798 308 return true;
799
800 extern int zq_screen_w, zq_screen_h;
801 if(set_gfx_mode(mode,resx,resy,zq_screen_w,zq_screen_h)!=0)
802 {
803 return false;
804 }
805
806 scrx = (resx-320)>>1;
807 scry = (resy-240)>>1;
808 for(int32_t q = 0; q < NUM_ZCMOUSE; ++q)
809 zcmouse[q] = NULL;
810 load_mouse();
811
812 for(int32_t i=240; i<256; i++)
813 RAMpal[i]=pal_gui[i];
814
815 zc_set_palette(RAMpal);
816 clear_to_color(screen,BLACK);
817
818 rest(wait);
819 return true;
820 308 }
821
822 316 void null_quest()
823 {
824
1/2
✓ Branch 0 taken 316 times.
✗ Branch 1 not taken.
316 std::string title_assets_path = "modules/classic/title_gfx.dat";
825
2/4
✓ Branch 0 taken 316 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 316 times.
316 if (get_last_loaded_qstpath() == title_assets_path)
826 return;
827
828 byte skip_flags[4];
829
2/2
✓ Branch 0 taken 316 times.
✓ Branch 1 taken 8216 times.
8532 for (int i = 0; i < skip_max; i++)
830
1/2
✓ Branch 0 taken 8216 times.
✗ Branch 1 not taken.
8216 set_bit(skip_flags, i, 1);
831
1/2
✓ Branch 0 taken 316 times.
✗ Branch 1 not taken.
316 set_bit(skip_flags, skip_tiles, 0);
832
1/2
✓ Branch 0 taken 316 times.
✗ Branch 1 not taken.
316 set_bit(skip_flags, skip_csets, 0);
833
1/2
✓ Branch 0 taken 316 times.
✗ Branch 1 not taken.
316 set_bit(skip_flags, skip_misc, 0); // needed for miscsfx (skip this and `tests/replays/demons_inferno/demons_inferno_1_of_2.zplay` fails).
834
1/2
✓ Branch 0 taken 316 times.
✗ Branch 1 not taken.
316 loadquest(title_assets_path.c_str(), &QHeader, &QMisc, tunes+ZC_MIDI_COUNT, false, skip_flags, 0, false);
835 316 sfxdat = 1;
836 // TODO: sfx.dat is ~1.2 MB. Could be better to break that up into individual files and load on demand / not at startup.
837 // TODO: can we cache the tiles/colordata so we don't have to read title_gfx.dat more than once?
838 // colordata is tiny, but tilebuf is huge, so limit that to just what the title screen needs.
839 // Another option: embed this data into the binary (`xxd -i resources/modules/classic/title_gfx.dat > title_gfx.h`)
840
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 316 times.
316 }
841
842 316 void init_NES_mode()
843 {
844 316 null_quest();
845 316 }
846
847 //----------------------------------------------------------------
848
849 qword trianglelines[16]=
850 {
851 0x0000000000000000ULL,
852 0xFD00000000000000ULL,
853 0xFDFD000000000000ULL,
854 0xFDFDFD0000000000ULL,
855 0xFDFDFDFD00000000ULL,
856 0xFDFDFDFDFD000000ULL,
857 0xFDFDFDFDFDFD0000ULL,
858 0xFDFDFDFDFDFDFD00ULL,
859 0xFDFDFDFDFDFDFDFDULL,
860 0x00FDFDFDFDFDFDFDULL,
861 0x0000FDFDFDFDFDFDULL,
862 0x000000FDFDFDFDFDULL,
863 0x00000000FDFDFDFDULL,
864 0x0000000000FDFDFDULL,
865 0x000000000000FDFDULL,
866 0x00000000000000FDULL,
867 };
868
869 word screen_triangles[29][32];
870
871 // the ULL suffixes are to prevent this warning:
872 // warning: integer constant is too large for "int32_t" type
873
874 qword triangles[4][16][8]= //[direction][value][line]
875 {
876 {
877 {
878 0x0000000000000000ULL,
879 0x0000000000000000ULL,
880 0x0000000000000000ULL,
881 0x0000000000000000ULL,
882 0x0000000000000000ULL,
883 0x0000000000000000ULL,
884 0x0000000000000000ULL,
885 0x0000000000000000ULL
886 },
887 {
888 0xFD00000000000000ULL,
889 0x0000000000000000ULL,
890 0x0000000000000000ULL,
891 0x0000000000000000ULL,
892 0x0000000000000000ULL,
893 0x0000000000000000ULL,
894 0x0000000000000000ULL,
895 0x0000000000000000ULL
896 },
897 {
898 0xFDFD000000000000ULL,
899 0xFD00000000000000ULL,
900 0x0000000000000000ULL,
901 0x0000000000000000ULL,
902 0x0000000000000000ULL,
903 0x0000000000000000ULL,
904 0x0000000000000000ULL,
905 0x0000000000000000ULL
906 },
907 {
908 0xFDFDFD0000000000ULL,
909 0xFDFD000000000000ULL,
910 0xFD00000000000000ULL,
911 0x0000000000000000ULL,
912 0x0000000000000000ULL,
913 0x0000000000000000ULL,
914 0x0000000000000000ULL,
915 0x0000000000000000ULL
916 },
917 {
918 0xFDFDFDFD00000000ULL,
919 0xFDFDFD0000000000ULL,
920 0xFDFD000000000000ULL,
921 0xFD00000000000000ULL,
922 0x0000000000000000ULL,
923 0x0000000000000000ULL,
924 0x0000000000000000ULL,
925 0x0000000000000000ULL
926 },
927 {
928 0xFDFDFDFDFD000000ULL,
929 0xFDFDFDFD00000000ULL,
930 0xFDFDFD0000000000ULL,
931 0xFDFD000000000000ULL,
932 0xFD00000000000000ULL,
933 0x0000000000000000ULL,
934 0x0000000000000000ULL,
935 0x0000000000000000ULL
936 },
937 {
938 0xFDFDFDFDFDFD0000ULL,
939 0xFDFDFDFDFD000000ULL,
940 0xFDFDFDFD00000000ULL,
941 0xFDFDFD0000000000ULL,
942 0xFDFD000000000000ULL,
943 0xFD00000000000000ULL,
944 0x0000000000000000ULL,
945 0x0000000000000000ULL
946 },
947 {
948 0xFDFDFDFDFDFDFD00ULL,
949 0xFDFDFDFDFDFD0000ULL,
950 0xFDFDFDFDFD000000ULL,
951 0xFDFDFDFD00000000ULL,
952 0xFDFDFD0000000000ULL,
953 0xFDFD000000000000ULL,
954 0xFD00000000000000ULL,
955 0x0000000000000000ULL
956 },
957 {
958 0xFDFDFDFDFDFDFDFDULL,
959 0xFDFDFDFDFDFDFD00ULL,
960 0xFDFDFDFDFDFD0000ULL,
961 0xFDFDFDFDFD000000ULL,
962 0xFDFDFDFD00000000ULL,
963 0xFDFDFD0000000000ULL,
964 0xFDFD000000000000ULL,
965 0xFD00000000000000ULL
966 },
967 {
968 0xFDFDFDFDFDFDFDFDULL,
969 0xFDFDFDFDFDFDFDFDULL,
970 0xFDFDFDFDFDFDFD00ULL,
971 0xFDFDFDFDFDFD0000ULL,
972 0xFDFDFDFDFD000000ULL,
973 0xFDFDFDFD00000000ULL,
974 0xFDFDFD0000000000ULL,
975 0xFDFD000000000000ULL
976 },
977 {
978 0xFDFDFDFDFDFDFDFDULL,
979 0xFDFDFDFDFDFDFDFDULL,
980 0xFDFDFDFDFDFDFDFDULL,
981 0xFDFDFDFDFDFDFD00ULL,
982 0xFDFDFDFDFDFD0000ULL,
983 0xFDFDFDFDFD000000ULL,
984 0xFDFDFDFD00000000ULL,
985 0xFDFDFD0000000000ULL
986 },
987 {
988 0xFDFDFDFDFDFDFDFDULL,
989 0xFDFDFDFDFDFDFDFDULL,
990 0xFDFDFDFDFDFDFDFDULL,
991 0xFDFDFDFDFDFDFDFDULL,
992 0xFDFDFDFDFDFDFD00ULL,
993 0xFDFDFDFDFDFD0000ULL,
994 0xFDFDFDFDFD000000ULL,
995 0xFDFDFDFD00000000ULL
996 },
997 {
998 0xFDFDFDFDFDFDFDFDULL,
999 0xFDFDFDFDFDFDFDFDULL,
1000 0xFDFDFDFDFDFDFDFDULL,
1001 0xFDFDFDFDFDFDFDFDULL,
1002 0xFDFDFDFDFDFDFDFDULL,
1003 0xFDFDFDFDFDFDFD00ULL,
1004 0xFDFDFDFDFDFD0000ULL,
1005 0xFDFDFDFDFD000000ULL
1006 },
1007 {
1008 0xFDFDFDFDFDFDFDFDULL,
1009 0xFDFDFDFDFDFDFDFDULL,
1010 0xFDFDFDFDFDFDFDFDULL,
1011 0xFDFDFDFDFDFDFDFDULL,
1012 0xFDFDFDFDFDFDFDFDULL,
1013 0xFDFDFDFDFDFDFDFDULL,
1014 0xFDFDFDFDFDFDFD00ULL,
1015 0xFDFDFDFDFDFD0000ULL
1016 },
1017 {
1018 0xFDFDFDFDFDFDFDFDULL,
1019 0xFDFDFDFDFDFDFDFDULL,
1020 0xFDFDFDFDFDFDFDFDULL,
1021 0xFDFDFDFDFDFDFDFDULL,
1022 0xFDFDFDFDFDFDFDFDULL,
1023 0xFDFDFDFDFDFDFDFDULL,
1024 0xFDFDFDFDFDFDFDFDULL,
1025 0xFDFDFDFDFDFDFD00ULL
1026 },
1027 {
1028 0xFDFDFDFDFDFDFDFDULL,
1029 0xFDFDFDFDFDFDFDFDULL,
1030 0xFDFDFDFDFDFDFDFDULL,
1031 0xFDFDFDFDFDFDFDFDULL,
1032 0xFDFDFDFDFDFDFDFDULL,
1033 0xFDFDFDFDFDFDFDFDULL,
1034 0xFDFDFDFDFDFDFDFDULL,
1035 0xFDFDFDFDFDFDFDFDULL
1036 }
1037 },
1038 {
1039 {
1040 0x0000000000000000ULL,
1041 0x0000000000000000ULL,
1042 0x0000000000000000ULL,
1043 0x0000000000000000ULL,
1044 0x0000000000000000ULL,
1045 0x0000000000000000ULL,
1046 0x0000000000000000ULL,
1047 0x0000000000000000ULL
1048 },
1049 {
1050 0x00000000000000FDULL,
1051 0x0000000000000000ULL,
1052 0x0000000000000000ULL,
1053 0x0000000000000000ULL,
1054 0x0000000000000000ULL,
1055 0x0000000000000000ULL,
1056 0x0000000000000000ULL,
1057 0x0000000000000000ULL
1058 },
1059 {
1060 0x000000000000FDFDULL,
1061 0x00000000000000FDULL,
1062 0x0000000000000000ULL,
1063 0x0000000000000000ULL,
1064 0x0000000000000000ULL,
1065 0x0000000000000000ULL,
1066 0x0000000000000000ULL,
1067 0x0000000000000000ULL
1068 },
1069 {
1070 0x0000000000FDFDFDULL,
1071 0x000000000000FDFDULL,
1072 0x00000000000000FDULL,
1073 0x0000000000000000ULL,
1074 0x0000000000000000ULL,
1075 0x0000000000000000ULL,
1076 0x0000000000000000ULL,
1077 0x0000000000000000ULL
1078 },
1079 {
1080 0x00000000FDFDFDFDULL,
1081 0x0000000000FDFDFDULL,
1082 0x000000000000FDFDULL,
1083 0x00000000000000FDULL,
1084 0x0000000000000000ULL,
1085 0x0000000000000000ULL,
1086 0x0000000000000000ULL,
1087 0x0000000000000000ULL
1088 },
1089 {
1090 0x000000FDFDFDFDFDULL,
1091 0x00000000FDFDFDFDULL,
1092 0x0000000000FDFDFDULL,
1093 0x000000000000FDFDULL,
1094 0x00000000000000FDULL,
1095 0x0000000000000000ULL,
1096 0x0000000000000000ULL,
1097 0x0000000000000000ULL
1098 },
1099 {
1100 0x0000FDFDFDFDFDFDULL,
1101 0x000000FDFDFDFDFDULL,
1102 0x00000000FDFDFDFDULL,
1103 0x0000000000FDFDFDULL,
1104 0x000000000000FDFDULL,
1105 0x00000000000000FDULL,
1106 0x0000000000000000ULL,
1107 0x0000000000000000ULL
1108 },
1109 {
1110 0x00FDFDFDFDFDFDFDULL,
1111 0x0000FDFDFDFDFDFDULL,
1112 0x000000FDFDFDFDFDULL,
1113 0x00000000FDFDFDFDULL,
1114 0x0000000000FDFDFDULL,
1115 0x000000000000FDFDULL,
1116 0x00000000000000FDULL,
1117 0x0000000000000000ULL
1118 },
1119 {
1120 0xFDFDFDFDFDFDFDFDULL,
1121 0x00FDFDFDFDFDFDFDULL,
1122 0x0000FDFDFDFDFDFDULL,
1123 0x000000FDFDFDFDFDULL,
1124 0x00000000FDFDFDFDULL,
1125 0x0000000000FDFDFDULL,
1126 0x000000000000FDFDULL,
1127 0x00000000000000FDULL
1128 },
1129 {
1130 0xFDFDFDFDFDFDFDFDULL,
1131 0xFDFDFDFDFDFDFDFDULL,
1132 0x00FDFDFDFDFDFDFDULL,
1133 0x0000FDFDFDFDFDFDULL,
1134 0x000000FDFDFDFDFDULL,
1135 0x00000000FDFDFDFDULL,
1136 0x0000000000FDFDFDULL,
1137 0x000000000000FDFDULL
1138 },
1139 {
1140 0xFDFDFDFDFDFDFDFDULL,
1141 0xFDFDFDFDFDFDFDFDULL,
1142 0xFDFDFDFDFDFDFDFDULL,
1143 0x00FDFDFDFDFDFDFDULL,
1144 0x0000FDFDFDFDFDFDULL,
1145 0x000000FDFDFDFDFDULL,
1146 0x00000000FDFDFDFDULL,
1147 0x0000000000FDFDFDULL
1148 },
1149 {
1150 0xFDFDFDFDFDFDFDFDULL,
1151 0xFDFDFDFDFDFDFDFDULL,
1152 0xFDFDFDFDFDFDFDFDULL,
1153 0xFDFDFDFDFDFDFDFDULL,
1154 0x00FDFDFDFDFDFDFDULL,
1155 0x0000FDFDFDFDFDFDULL,
1156 0x000000FDFDFDFDFDULL,
1157 0x00000000FDFDFDFDULL
1158 },
1159 {
1160 0xFDFDFDFDFDFDFDFDULL,
1161 0xFDFDFDFDFDFDFDFDULL,
1162 0xFDFDFDFDFDFDFDFDULL,
1163 0xFDFDFDFDFDFDFDFDULL,
1164 0xFDFDFDFDFDFDFDFDULL,
1165 0x00FDFDFDFDFDFDFDULL,
1166 0x0000FDFDFDFDFDFDULL,
1167 0x000000FDFDFDFDFDULL
1168 },
1169 {
1170 0xFDFDFDFDFDFDFDFDULL,
1171 0xFDFDFDFDFDFDFDFDULL,
1172 0xFDFDFDFDFDFDFDFDULL,
1173 0xFDFDFDFDFDFDFDFDULL,
1174 0xFDFDFDFDFDFDFDFDULL,
1175 0xFDFDFDFDFDFDFDFDULL,
1176 0x00FDFDFDFDFDFDFDULL,
1177 0x0000FDFDFDFDFDFDULL
1178 },
1179 {
1180 0xFDFDFDFDFDFDFDFDULL,
1181 0xFDFDFDFDFDFDFDFDULL,
1182 0xFDFDFDFDFDFDFDFDULL,
1183 0xFDFDFDFDFDFDFDFDULL,
1184 0xFDFDFDFDFDFDFDFDULL,
1185 0xFDFDFDFDFDFDFDFDULL,
1186 0xFDFDFDFDFDFDFDFDULL,
1187 0x00FDFDFDFDFDFDFDULL
1188 },
1189 {
1190 0xFDFDFDFDFDFDFDFDULL,
1191 0xFDFDFDFDFDFDFDFDULL,
1192 0xFDFDFDFDFDFDFDFDULL,
1193 0xFDFDFDFDFDFDFDFDULL,
1194 0xFDFDFDFDFDFDFDFDULL,
1195 0xFDFDFDFDFDFDFDFDULL,
1196 0xFDFDFDFDFDFDFDFDULL,
1197 0xFDFDFDFDFDFDFDFDULL
1198 }
1199 },
1200 {
1201 {
1202 0x0000000000000000ULL,
1203 0x0000000000000000ULL,
1204 0x0000000000000000ULL,
1205 0x0000000000000000ULL,
1206 0x0000000000000000ULL,
1207 0x0000000000000000ULL,
1208 0x0000000000000000ULL,
1209 0x0000000000000000ULL
1210 },
1211 {
1212 0x0000000000000000ULL,
1213 0x0000000000000000ULL,
1214 0x0000000000000000ULL,
1215 0x0000000000000000ULL,
1216 0x0000000000000000ULL,
1217 0x0000000000000000ULL,
1218 0x0000000000000000ULL,
1219 0xFD00000000000000ULL
1220 },
1221 {
1222 0x0000000000000000ULL,
1223 0x0000000000000000ULL,
1224 0x0000000000000000ULL,
1225 0x0000000000000000ULL,
1226 0x0000000000000000ULL,
1227 0x0000000000000000ULL,
1228 0xFD00000000000000ULL,
1229 0xFDFD000000000000ULL
1230 },
1231 {
1232 0x0000000000000000ULL,
1233 0x0000000000000000ULL,
1234 0x0000000000000000ULL,
1235 0x0000000000000000ULL,
1236 0x0000000000000000ULL,
1237 0xFD00000000000000ULL,
1238 0xFDFD000000000000ULL,
1239 0xFDFDFD0000000000ULL
1240 },
1241 {
1242 0x0000000000000000ULL,
1243 0x0000000000000000ULL,
1244 0x0000000000000000ULL,
1245 0x0000000000000000ULL,
1246 0xFD00000000000000ULL,
1247 0xFDFD000000000000ULL,
1248 0xFDFDFD0000000000ULL,
1249 0xFDFDFDFD00000000ULL
1250 },
1251 {
1252 0x0000000000000000ULL,
1253 0x0000000000000000ULL,
1254 0x0000000000000000ULL,
1255 0xFD00000000000000ULL,
1256 0xFDFD000000000000ULL,
1257 0xFDFDFD0000000000ULL,
1258 0xFDFDFDFD00000000ULL,
1259 0xFDFDFDFDFD000000ULL
1260 },
1261 {
1262 0x0000000000000000ULL,
1263 0x0000000000000000ULL,
1264 0xFD00000000000000ULL,
1265 0xFDFD000000000000ULL,
1266 0xFDFDFD0000000000ULL,
1267 0xFDFDFDFD00000000ULL,
1268 0xFDFDFDFDFD000000ULL,
1269 0xFDFDFDFDFDFD0000ULL
1270 },
1271 {
1272 0x0000000000000000ULL,
1273 0xFD00000000000000ULL,
1274 0xFDFD000000000000ULL,
1275 0xFDFDFD0000000000ULL,
1276 0xFDFDFDFD00000000ULL,
1277 0xFDFDFDFDFD000000ULL,
1278 0xFDFDFDFDFDFD0000ULL,
1279 0xFDFDFDFDFDFDFD00ULL
1280 },
1281 {
1282 0xFD00000000000000ULL,
1283 0xFDFD000000000000ULL,
1284 0xFDFDFD0000000000ULL,
1285 0xFDFDFDFD00000000ULL,
1286 0xFDFDFDFDFD000000ULL,
1287 0xFDFDFDFDFDFD0000ULL,
1288 0xFDFDFDFDFDFDFD00ULL,
1289 0xFDFDFDFDFDFDFDFDULL
1290 },
1291 {
1292 0xFDFD000000000000ULL,
1293 0xFDFDFD0000000000ULL,
1294 0xFDFDFDFD00000000ULL,
1295 0xFDFDFDFDFD000000ULL,
1296 0xFDFDFDFDFDFD0000ULL,
1297 0xFDFDFDFDFDFDFD00ULL,
1298 0xFDFDFDFDFDFDFDFDULL,
1299 0xFDFDFDFDFDFDFDFDULL
1300 },
1301 {
1302 0xFDFDFD0000000000ULL,
1303 0xFDFDFDFD00000000ULL,
1304 0xFDFDFDFDFD000000ULL,
1305 0xFDFDFDFDFDFD0000ULL,
1306 0xFDFDFDFDFDFDFD00ULL,
1307 0xFDFDFDFDFDFDFDFDULL,
1308 0xFDFDFDFDFDFDFDFDULL,
1309 0xFDFDFDFDFDFDFDFDULL
1310 },
1311 {
1312 0xFDFDFDFD00000000ULL,
1313 0xFDFDFDFDFD000000ULL,
1314 0xFDFDFDFDFDFD0000ULL,
1315 0xFDFDFDFDFDFDFD00ULL,
1316 0xFDFDFDFDFDFDFDFDULL,
1317 0xFDFDFDFDFDFDFDFDULL,
1318 0xFDFDFDFDFDFDFDFDULL,
1319 0xFDFDFDFDFDFDFDFDULL
1320 },
1321 {
1322 0xFDFDFDFDFD000000ULL,
1323 0xFDFDFDFDFDFD0000ULL,
1324 0xFDFDFDFDFDFDFD00ULL,
1325 0xFDFDFDFDFDFDFDFDULL,
1326 0xFDFDFDFDFDFDFDFDULL,
1327 0xFDFDFDFDFDFDFDFDULL,
1328 0xFDFDFDFDFDFDFDFDULL,
1329 0xFDFDFDFDFDFDFDFDULL
1330 },
1331 {
1332 0xFDFDFDFDFDFD0000ULL,
1333 0xFDFDFDFDFDFDFD00ULL,
1334 0xFDFDFDFDFDFDFDFDULL,
1335 0xFDFDFDFDFDFDFDFDULL,
1336 0xFDFDFDFDFDFDFDFDULL,
1337 0xFDFDFDFDFDFDFDFDULL,
1338 0xFDFDFDFDFDFDFDFDULL,
1339 0xFDFDFDFDFDFDFDFDULL
1340 },
1341 {
1342 0xFDFDFDFDFDFDFD00ULL,
1343 0xFDFDFDFDFDFDFDFDULL,
1344 0xFDFDFDFDFDFDFDFDULL,
1345 0xFDFDFDFDFDFDFDFDULL,
1346 0xFDFDFDFDFDFDFDFDULL,
1347 0xFDFDFDFDFDFDFDFDULL,
1348 0xFDFDFDFDFDFDFDFDULL,
1349 0xFDFDFDFDFDFDFDFDULL
1350 },
1351 {
1352 0xFDFDFDFDFDFDFDFDULL,
1353 0xFDFDFDFDFDFDFDFDULL,
1354 0xFDFDFDFDFDFDFDFDULL,
1355 0xFDFDFDFDFDFDFDFDULL,
1356 0xFDFDFDFDFDFDFDFDULL,
1357 0xFDFDFDFDFDFDFDFDULL,
1358 0xFDFDFDFDFDFDFDFDULL,
1359 0xFDFDFDFDFDFDFDFDULL
1360 }
1361 },
1362 {
1363 {
1364 0x0000000000000000ULL,
1365 0x0000000000000000ULL,
1366 0x0000000000000000ULL,
1367 0x0000000000000000ULL,
1368 0x0000000000000000ULL,
1369 0x0000000000000000ULL,
1370 0x0000000000000000ULL,
1371 0x0000000000000000ULL
1372 },
1373 {
1374 0x0000000000000000ULL,
1375 0x0000000000000000ULL,
1376 0x0000000000000000ULL,
1377 0x0000000000000000ULL,
1378 0x0000000000000000ULL,
1379 0x0000000000000000ULL,
1380 0x0000000000000000ULL,
1381 0x00000000000000FDULL
1382 },
1383 {
1384 0x0000000000000000ULL,
1385 0x0000000000000000ULL,
1386 0x0000000000000000ULL,
1387 0x0000000000000000ULL,
1388 0x0000000000000000ULL,
1389 0x0000000000000000ULL,
1390 0x00000000000000FDULL,
1391 0x000000000000FDFDULL
1392 },
1393 {
1394 0x0000000000000000ULL,
1395 0x0000000000000000ULL,
1396 0x0000000000000000ULL,
1397 0x0000000000000000ULL,
1398 0x0000000000000000ULL,
1399 0x00000000000000FDULL,
1400 0x000000000000FDFDULL,
1401 0x0000000000FDFDFDULL
1402 },
1403 {
1404 0x0000000000000000ULL,
1405 0x0000000000000000ULL,
1406 0x0000000000000000ULL,
1407 0x0000000000000000ULL,
1408 0x00000000000000FDULL,
1409 0x000000000000FDFDULL,
1410 0x0000000000FDFDFDULL,
1411 0x00000000FDFDFDFDULL
1412 },
1413 {
1414 0x0000000000000000ULL,
1415 0x0000000000000000ULL,
1416 0x0000000000000000ULL,
1417 0x00000000000000FDULL,
1418 0x000000000000FDFDULL,
1419 0x0000000000FDFDFDULL,
1420 0x00000000FDFDFDFDULL,
1421 0x000000FDFDFDFDFDULL
1422 },
1423 {
1424 0x0000000000000000ULL,
1425 0x0000000000000000ULL,
1426 0x00000000000000FDULL,
1427 0x000000000000FDFDULL,
1428 0x0000000000FDFDFDULL,
1429 0x00000000FDFDFDFDULL,
1430 0x000000FDFDFDFDFDULL,
1431 0x0000FDFDFDFDFDFDULL
1432 },
1433 {
1434 0x0000000000000000ULL,
1435 0x00000000000000FDULL,
1436 0x000000000000FDFDULL,
1437 0x0000000000FDFDFDULL,
1438 0x00000000FDFDFDFDULL,
1439 0x000000FDFDFDFDFDULL,
1440 0x0000FDFDFDFDFDFDULL,
1441 0x00FDFDFDFDFDFDFDULL
1442 },
1443 {
1444 0x00000000000000FDULL,
1445 0x000000000000FDFDULL,
1446 0x0000000000FDFDFDULL,
1447 0x00000000FDFDFDFDULL,
1448 0x000000FDFDFDFDFDULL,
1449 0x0000FDFDFDFDFDFDULL,
1450 0x00FDFDFDFDFDFDFDULL,
1451 0xFDFDFDFDFDFDFDFDULL
1452 },
1453 {
1454 0x000000000000FDFDULL,
1455 0x0000000000FDFDFDULL,
1456 0x00000000FDFDFDFDULL,
1457 0x000000FDFDFDFDFDULL,
1458 0x0000FDFDFDFDFDFDULL,
1459 0x00FDFDFDFDFDFDFDULL,
1460 0xFDFDFDFDFDFDFDFDULL,
1461 0xFDFDFDFDFDFDFDFDULL
1462 },
1463 {
1464 0x0000000000FDFDFDULL,
1465 0x00000000FDFDFDFDULL,
1466 0x000000FDFDFDFDFDULL,
1467 0x0000FDFDFDFDFDFDULL,
1468 0x00FDFDFDFDFDFDFDULL,
1469 0xFDFDFDFDFDFDFDFDULL,
1470 0xFDFDFDFDFDFDFDFDULL,
1471 0xFDFDFDFDFDFDFDFDULL
1472 },
1473 {
1474 0x00000000FDFDFDFDULL,
1475 0x000000FDFDFDFDFDULL,
1476 0x0000FDFDFDFDFDFDULL,
1477 0x00FDFDFDFDFDFDFDULL,
1478 0xFDFDFDFDFDFDFDFDULL,
1479 0xFDFDFDFDFDFDFDFDULL,
1480 0xFDFDFDFDFDFDFDFDULL,
1481 0xFDFDFDFDFDFDFDFDULL
1482 },
1483 {
1484 0x000000FDFDFDFDFDULL,
1485 0x0000FDFDFDFDFDFDULL,
1486 0x00FDFDFDFDFDFDFDULL,
1487 0xFDFDFDFDFDFDFDFDULL,
1488 0xFDFDFDFDFDFDFDFDULL,
1489 0xFDFDFDFDFDFDFDFDULL,
1490 0xFDFDFDFDFDFDFDFDULL,
1491 0xFDFDFDFDFDFDFDFDULL
1492 },
1493 {
1494 0x0000FDFDFDFDFDFDULL,
1495 0x00FDFDFDFDFDFDFDULL,
1496 0xFDFDFDFDFDFDFDFDULL,
1497 0xFDFDFDFDFDFDFDFDULL,
1498 0xFDFDFDFDFDFDFDFDULL,
1499 0xFDFDFDFDFDFDFDFDULL,
1500 0xFDFDFDFDFDFDFDFDULL,
1501 0xFDFDFDFDFDFDFDFDULL
1502 },
1503 {
1504 0x00FDFDFDFDFDFDFDULL,
1505 0xFDFDFDFDFDFDFDFDULL,
1506 0xFDFDFDFDFDFDFDFDULL,
1507 0xFDFDFDFDFDFDFDFDULL,
1508 0xFDFDFDFDFDFDFDFDULL,
1509 0xFDFDFDFDFDFDFDFDULL,
1510 0xFDFDFDFDFDFDFDFDULL,
1511 0xFDFDFDFDFDFDFDFDULL
1512 },
1513 {
1514 0xFDFDFDFDFDFDFDFDULL,
1515 0xFDFDFDFDFDFDFDFDULL,
1516 0xFDFDFDFDFDFDFDFDULL,
1517 0xFDFDFDFDFDFDFDFDULL,
1518 0xFDFDFDFDFDFDFDFDULL,
1519 0xFDFDFDFDFDFDFDFDULL,
1520 0xFDFDFDFDFDFDFDFDULL,
1521 0xFDFDFDFDFDFDFDFDULL
1522 }
1523 }
1524 };
1525
1526 static bool is_opening_screen;
1527 int32_t black_opening_count=0;
1528 int32_t black_opening_x,black_opening_y;
1529 int32_t black_opening_shape;
1530
1531 3237 int32_t choose_opening_shape()
1532 {
1533 // First, count how many bits are set
1534 3237 int32_t numBits=0;
1535 int32_t bitCounter;
1536
1537
2/2
✓ Branch 0 taken 16185 times.
✓ Branch 1 taken 3237 times.
19422 for(int32_t i=0; i<bosMAX; i++)
1538 {
1539
2/2
✓ Branch 0 taken 12732 times.
✓ Branch 1 taken 3453 times.
16185 if(COOLSCROLL&(1<<i))
1540 3453 numBits++;
1541 16185 }
1542
1543 // Shouldn't happen...
1544
1/2
✓ Branch 0 taken 3237 times.
✗ Branch 1 not taken.
3237 if(numBits==0)
1545 return bosCIRCLE;
1546
1547 // Pick a bit
1548 3237 bitCounter=zc_rand()%numBits+1;
1549
1550
2/2
✓ Branch 0 taken 4431 times.
✓ Branch 1 taken 26 times.
4457 for(int32_t i=0; i<bosMAX; i++)
1551 {
1552 // If this bit is set, decrement the bit counter
1553
2/2
✓ Branch 0 taken 1064 times.
✓ Branch 1 taken 3367 times.
4431 if(COOLSCROLL&(1<<i))
1554 3367 bitCounter--;
1555
1556 // When the counter hits 0, return a value based on
1557 // which bit it stopped on.
1558 // Reminder: enum {bosCIRCLE=0, bosOVAL, bosTRIANGLE, bosSMAS, bosFADEBLACK, bosMAX};
1559
2/2
✓ Branch 0 taken 3211 times.
✓ Branch 1 taken 1220 times.
4431 if(bitCounter==0)
1560 3211 return i;
1561 1220 }
1562
1563 // Shouldn't be necessary, but the compiler might complain, at least
1564 26 return bosCIRCLE;
1565 3237 }
1566
1567 738 void close_black_opening(int32_t x, int32_t y, bool wait, int32_t shape)
1568 {
1569 738 x -= viewport.x;
1570 738 y -= viewport.y;
1571
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 728 times.
738 black_opening_shape= (shape>-1 ? shape : choose_opening_shape());
1572
1573 738 int32_t w=framebuf->w, h=framebuf->h;
1574 738 int32_t blockrows=h/8, blockcolumns=32;
1575 738 int32_t xoffset=(x-(w/2))/8, yoffset=(y-(h/2))/8;
1576
1577
2/2
✓ Branch 0 taken 20664 times.
✓ Branch 1 taken 738 times.
21402 for(int32_t blockrow=0; blockrow<blockrows; ++blockrow) //30
1578 {
1579
2/2
✓ Branch 0 taken 661248 times.
✓ Branch 1 taken 20664 times.
681912 for(int32_t blockcolumn=0; blockcolumn<blockcolumns; ++blockcolumn) //40
1580 {
1581
2/2
✓ Branch 0 taken 273313 times.
✓ Branch 1 taken 387935 times.
661248 screen_triangles[blockrow][blockcolumn]=zc_max(abs(int32_t(double(blockcolumns-1)/2-blockcolumn+xoffset)),abs(int32_t(double(blockrows-1)/2-blockrow+yoffset)))|0x0100|((blockrow-yoffset<blockrows/2)?0:0x8000)|((blockcolumn-xoffset<blockcolumns/2)?0x4000:0);
1582 661248 }
1583 20664 }
1584
1585 738 black_opening_count = 66;
1586 738 black_opening_x = x;
1587 738 black_opening_y = y;
1588 738 lensclk = 0;
1589 //black_opening_shape=(black_opening_shape+1)%bosMAX;
1590
1591
1592
1/2
✓ Branch 0 taken 738 times.
✗ Branch 1 not taken.
738 if(black_opening_shape == bosFADEBLACK)
1593 {
1594 refreshTints();
1595 memcpy(tempblackpal, RAMpal, sizeof(RAMpal)); //Store palette in temp palette for fade effect
1596 }
1597
2/2
✓ Branch 0 taken 724 times.
✓ Branch 1 taken 14 times.
738 if(wait)
1598 {
1599 14 FFCore.warpScriptCheck();
1600
2/2
✓ Branch 0 taken 14 times.
✓ Branch 1 taken 924 times.
938 for(int32_t i=0; i<66; i++)
1601 {
1602 924 draw_screen();
1603 924 advanceframe(true);
1604
1605
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 924 times.
924 if(Quit)
1606 {
1607 break;
1608 }
1609 924 }
1610 14 }
1611 738 }
1612
1613 2519 void open_black_opening(int32_t x, int32_t y, bool wait, int32_t shape)
1614 {
1615 2519 x -= viewport.x;
1616 2519 y -= viewport.y;
1617
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 2509 times.
2519 black_opening_shape= (shape>-1 ? shape : choose_opening_shape());
1618
1619 2519 int32_t w=framebuf->w, h=framebuf->h;
1620 2519 int32_t blockrows=h/8, blockcolumns=32;
1621 2519 int32_t xoffset=(x-(w/2))/8, yoffset=(y-(h/2))/8;
1622
1623
2/2
✓ Branch 0 taken 70631 times.
✓ Branch 1 taken 2519 times.
73150 for(int32_t blockrow=0; blockrow<blockrows; ++blockrow) //30
1624 {
1625
2/2
✓ Branch 0 taken 2260192 times.
✓ Branch 1 taken 70631 times.
2330823 for(int32_t blockcolumn=0; blockcolumn<blockcolumns; ++blockcolumn) //40
1626 {
1627
2/2
✓ Branch 0 taken 1118616 times.
✓ Branch 1 taken 1141576 times.
2260192 screen_triangles[blockrow][blockcolumn]=zc_max(abs(int32_t(double(blockcolumns-1)/2-blockcolumn+xoffset)),abs(int32_t(double(blockrows-1)/2-blockrow+yoffset)))|0x0100|((blockrow-yoffset<blockrows/2)?0:0x8000)|((blockcolumn-xoffset<blockcolumns/2)?0x4000:0);
1628 2260192 }
1629 70631 }
1630
1631 2519 black_opening_count = -66;
1632 2519 black_opening_x = x;
1633 2519 black_opening_y = y;
1634 2519 lensclk = 0;
1635
1/2
✓ Branch 0 taken 2519 times.
✗ Branch 1 not taken.
2519 if(black_opening_shape == bosFADEBLACK)
1636 {
1637 refreshTints();
1638 memcpy(tempblackpal, RAMpal, sizeof(RAMpal)); //Store palette in temp palette for fade effect
1639 }
1640
2/2
✓ Branch 0 taken 367 times.
✓ Branch 1 taken 2152 times.
2519 if(wait)
1641 {
1642 2152 FFCore.warpScriptCheck();
1643
2/2
✓ Branch 0 taken 2151 times.
✓ Branch 1 taken 142043 times.
144194 for(int32_t i=0; i<66; i++)
1644 {
1645 142043 draw_screen();
1646 142043 advanceframe(true);
1647
1648
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 142042 times.
142043 if(Quit)
1649 {
1650 1 break;
1651 }
1652 142042 }
1653 2152 }
1654 2519 }
1655
1656 214194 void black_opening(BITMAP *dest,int32_t x,int32_t y,int32_t a,int32_t max_a)
1657 {
1658 214194 clear_to_color(tmp_scr,BLACK);
1659 214194 int32_t w=dest->w, h=dest->h;
1660
1661
4/6
✗ Branch 0 not taken.
✓ Branch 1 taken 9636 times.
✓ Branch 2 taken 1980 times.
✓ Branch 3 taken 20328 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 182250 times.
214194 switch(black_opening_shape)
1662 {
1663 case bosOVAL:
1664 {
1665 9636 double new_w=(w/2)+abs(w/2-x);
1666 9636 double new_h=(h/2)+abs(h/2-y);
1667 9636 double b=sqrt(((new_w*new_w)/4)+(new_h*new_h));
1668 9636 ellipsefill(tmp_scr,x,y,int32_t(2*a*b/max_a)/8*8,int32_t(a*b/max_a)/8*8,0);
1669 9636 break;
1670 }
1671
1672 case bosTRIANGLE:
1673 {
1674 1980 double new_w=(w/2)+abs(w/2-x);
1675 1980 double new_h=(h/2)+abs(h/2-y);
1676 1980 double r=a*(new_w*sqrt((double)3)+new_h)/max_a;
1677 1980 double P2= (PI/2);
1678 1980 double P23=(2*PI/3);
1679 1980 double P43=(4*PI/3);
1680 1980 double Pa= (-4*PI*a/(3*max_a));
1681 1980 double angle=P2+Pa;
1682 1980 double a0=angle;
1683 1980 double a2=angle+P23;
1684 1980 double a4=angle+P43;
1685 3960 triangle(tmp_scr, x+int32_t(zc::math::Cos(a0)*r), y-int32_t(zc::math::Sin(a0)*r),
1686 1980 x+int32_t(zc::math::Cos(a2)*r), y-int32_t(zc::math::Sin(a2)*r),
1687 1980 x+int32_t(zc::math::Cos(a4)*r), y-int32_t(zc::math::Sin(a4)*r),
1688 0);
1689 1980 break;
1690 }
1691
1692 case bosSMAS:
1693 {
1694
2/2
✓ Branch 0 taken 7260 times.
✓ Branch 1 taken 13068 times.
20328 int32_t distance=zc_max(abs(w/2-x),abs(h/2-y))/8;
1695
1696
2/2
✓ Branch 0 taken 569184 times.
✓ Branch 1 taken 20328 times.
589512 for(int32_t blockrow=0; blockrow<h/8; ++blockrow) //30
1697 {
1698
2/2
✓ Branch 0 taken 4553472 times.
✓ Branch 1 taken 569184 times.
5122656 for(int32_t linerow=0; linerow<8; ++linerow)
1699 {
1700 4553472 qword *triangleline=(qword*)(tmp_scr->line[(blockrow*8+linerow)]);
1701
1702
2/2
✓ Branch 0 taken 145711104 times.
✓ Branch 1 taken 4553472 times.
150264576 for(int32_t blockcolumn=0; blockcolumn<32; ++blockcolumn) //40
1703 {
1704 437133312 *triangleline=triangles[(screen_triangles[blockrow][blockcolumn]&0xC000)>>14]
1705
6/6
✓ Branch 0 taken 105268072 times.
✓ Branch 1 taken 40443032 times.
✓ Branch 2 taken 96140976 times.
✓ Branch 3 taken 49570128 times.
✓ Branch 4 taken 55697944 times.
✓ Branch 5 taken 40443032 times.
145711104 [zc_min(zc_max((((31+distance)*(max_a-a)/max_a)+((screen_triangles[blockrow][blockcolumn]&0x0FFF)-0x0100)-(15+distance)),0),15)]
1706 145711104 [linerow];
1707 145711104 ++triangleline;
1708 145711104 }
1709 4553472 }
1710 569184 }
1711
1712 20328 break;
1713 }
1714
1715 case bosFADEBLACK:
1716 {
1717 if(black_opening_count<0)
1718 {
1719 black_fade(zc_min(-black_opening_count,63));
1720 }
1721 else if(black_opening_count>0)
1722 {
1723 black_fade(63-zc_max(black_opening_count-3,0));
1724 }
1725 else black_fade(0);
1726 return; //no blitting from tmp_scr!
1727 }
1728
1729 182250 case bosCIRCLE:
1730 default:
1731 {
1732 182250 double new_w=(w/2)+abs(w/2-x);
1733 182250 double new_h=(h/2)+abs(h/2-y);
1734 182250 int32_t r=int32_t(sqrt((new_w*new_w)+(new_h*new_h))*a/max_a);
1735 //circlefill(tmp_scr,x,y,a<<3,0);
1736 182250 circlefill(tmp_scr,x,y,r,0);
1737 182250 break;
1738 }
1739 }
1740
1741 214194 masked_blit(tmp_scr,dest,0,0,0,0,320,240);
1742 214194 }
1743
1744 // fadeamnt is 0-63
1745 void black_fade(int32_t fadeamnt)
1746 {
1747 fadeamnt = _rgb_scale_6[fadeamnt];
1748 for(int32_t i=0; i < 0xEF; i++)
1749 {
1750 RAMpal[i].r = vbound(tempblackpal[i].r-fadeamnt,0,255);
1751 RAMpal[i].g = vbound(tempblackpal[i].g-fadeamnt,0,255);
1752 RAMpal[i].b = vbound(tempblackpal[i].b-fadeamnt,0,255);
1753 }
1754
1755 refreshpal = true;
1756 }
1757
1758 //----------------------------------------------------------------
1759
1760 198413517 bool item_disabled(int32_t item) //is this item disabled?
1761 {
1762
2/2
✓ Branch 0 taken 14456540 times.
✓ Branch 1 taken 183956977 times.
198413517 return (unsigned(item) < MAXITEMS && game->items_off[item] != 0);
1763 }
1764
1765 15494378 bool can_use_item(int32_t item_type, int32_t item) //can Hero use this item?
1766 {
1767
2/2
✓ Branch 0 taken 254624 times.
✓ Branch 1 taken 15239754 times.
15494378 if(current_item(item_type, true) >=item)
1768 {
1769 254624 return true;
1770 }
1771
1772 15239754 return false;
1773 15494378 }
1774
1775 42856623 bool has_item(int32_t item_type, int32_t it) //does Hero possess this item?
1776 {
1777
5/9
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 4340661 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 337472 times.
✓ Branch 6 taken 28243397 times.
✓ Branch 7 taken 9740027 times.
✓ Branch 8 taken 195066 times.
42856623 switch(item_type)
1778 {
1779 case itype_bomb:
1780 case itype_sbomb:
1781 {
1782 int32_t itemid = getItemID(itemsbuf, item_type, it);
1783
1784 if(itemid == -1)
1785 return false;
1786
1787 return (game->get_item(itemid));
1788 }
1789
1790 case itype_clock:
1791 {
1792 4340661 int32_t itemid = getItemID(itemsbuf, item_type, it);
1793
1794
2/4
✓ Branch 0 taken 4340661 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4340661 times.
✗ Branch 3 not taken.
4340661 if(itemid != -1 && (itemsbuf[itemid].flags & item_flag1)) //Active clock
1795 return (game->get_item(itemid));
1796 4340661 return Hero.getClock()?1:0;
1797 }
1798
1799 case itype_key:
1800 return (game->get_keys()>0);
1801
1802 case itype_magiccontainer:
1803 return (game->get_maxmagic()>=game->get_mp_per_block());
1804
1805 case itype_triforcepiece: //it: -2=any, -1=current level, other=that level
1806 {
1807
1/3
✓ Branch 0 taken 337472 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
337472 switch(it)
1808 {
1809 case -2:
1810 {
1811 for(int32_t i=0; i<MAXLEVELS; i++)
1812 {
1813 if(game->lvlitems[i]&liTRIFORCE)
1814 {
1815 return true;
1816 }
1817 }
1818
1819 return false;
1820 }
1821
1822 case -1:
1823 return (game->lvlitems[dlevel]&liTRIFORCE);
1824
1825 default:
1826
2/4
✓ Branch 0 taken 337472 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 337472 times.
337472 if(it>=0&&it<MAXLEVELS)
1827 {
1828 337472 return (game->lvlitems[it]&liTRIFORCE);
1829 }
1830
1831 break;
1832 }
1833
1834 return 0;
1835 }
1836
1837 case itype_map: //it: -2=any, -1=current level, other=that level
1838 {
1839
2/3
✓ Branch 0 taken 534304 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 27709093 times.
28243397 switch(it)
1840 {
1841 case -2:
1842 {
1843 for(int32_t i=0; i<MAXLEVELS; i++)
1844 {
1845 if(game->lvlitems[i]&liMAP)
1846 {
1847 return true;
1848 }
1849 }
1850
1851 return false;
1852 }
1853
1854 case -1:
1855 27709093 return (game->lvlitems[dlevel]&liMAP)!=0;
1856
1857 default:
1858
2/4
✓ Branch 0 taken 534304 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 534304 times.
534304 if(it>=0&&it<MAXLEVELS)
1859 {
1860 534304 return (game->lvlitems[it]&liMAP)!=0;
1861 }
1862
1863 break;
1864 }
1865
1866 return 0;
1867 }
1868
1869 case itype_compass: //it: -2=any, -1=current level, other=that level
1870 {
1871
1/3
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 9740027 times.
9740027 switch(it)
1872 {
1873 case -2:
1874 {
1875 for(int32_t i=0; i<MAXLEVELS; i++)
1876 {
1877 if(game->lvlitems[i]&liCOMPASS)
1878 {
1879 return true;
1880 }
1881 }
1882
1883 return false;
1884 }
1885
1886 case -1:
1887 9740027 return (game->lvlitems[dlevel]&liCOMPASS)!=0;
1888
1889 default:
1890 if(it>=0&&it<MAXLEVELS)
1891 {
1892 return (game->lvlitems[it]&liCOMPASS)!=0;
1893 }
1894
1895 break;
1896 }
1897 return 0;
1898 }
1899
1900 case itype_bosskey: //it: -2=any, -1=current level, other=that level
1901 {
1902
1/3
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 195066 times.
195066 switch(it)
1903 {
1904 case -2:
1905 {
1906 for(int32_t i=0; i<MAXLEVELS; i++)
1907 {
1908 if(game->lvlitems[i]&liBOSSKEY)
1909 {
1910 return true;
1911 }
1912 }
1913
1914 return false;
1915 }
1916
1917 case -1:
1918 195066 return (game->lvlitems[dlevel]&liBOSSKEY)?1:0;
1919
1920 default:
1921 if(it>=0&&it<MAXLEVELS)
1922 {
1923 return (game->lvlitems[it]&liBOSSKEY)?1:0;
1924 }
1925 break;
1926 }
1927 return 0;
1928 }
1929
1930 default:
1931 int32_t itemid = getItemID(itemsbuf, item_type, it);
1932
1933 if(itemid == -1)
1934 return false;
1935
1936 return game->get_item(itemid);
1937 }
1938 42856623 }
1939
1940 148375646 int current_item(int item_type, bool checkmagic, bool jinx_check, bool check_bunny)
1941 {
1942
9/9
✓ Branch 0 taken 4340661 times.
✓ Branch 1 taken 113650358 times.
✓ Branch 2 taken 4340661 times.
✓ Branch 3 taken 4340661 times.
✓ Branch 4 taken 4340661 times.
✓ Branch 5 taken 4340661 times.
✓ Branch 6 taken 4340661 times.
✓ Branch 7 taken 4340661 times.
✓ Branch 8 taken 4340661 times.
148375646 switch(item_type)
1943 {
1944 case itype_clock:
1945 {
1946 4340661 int maxid = current_item_id(item_type, checkmagic, jinx_check, check_bunny);
1947
1948
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 4340661 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
4340661 if(maxid != -1 && (itemsbuf[maxid].flags & item_flag1)) //Active clock
1949 return itemsbuf[maxid].fam_type;
1950
1951 4340661 return has_item(itype_clock,1) ? 1 : 0;
1952 }
1953
1954 case itype_key:
1955 4340661 return game->get_keys();
1956
1957 case itype_lkey:
1958 4340661 return game->lvlkeys[get_dlevel()];
1959
1960 case itype_magiccontainer:
1961 4340661 return game->get_maxmagic()/game->get_mp_per_block();
1962
1963 case itype_triforcepiece:
1964 {
1965 4340661 int count=0;
1966
1967
2/2
✓ Branch 0 taken 2222418432 times.
✓ Branch 1 taken 4340661 times.
2226759093 for(int i=0; i<MAXLEVELS; i++)
1968 {
1969 2222418432 count+=(game->lvlitems[i]&liTRIFORCE)?1:0;
1970 2222418432 }
1971
1972 4340661 return count;
1973 }
1974
1975 case itype_map:
1976 {
1977 4340661 int count=0;
1978
1979
2/2
✓ Branch 0 taken 2222418432 times.
✓ Branch 1 taken 4340661 times.
2226759093 for(int i=0; i<MAXLEVELS; i++)
1980 {
1981 2222418432 count+=(game->lvlitems[i]&liMAP)?1:0;
1982 2222418432 }
1983
1984 4340661 return count;
1985 }
1986
1987 case itype_compass:
1988 {
1989 4340661 int count=0;
1990
1991
2/2
✓ Branch 0 taken 2222418432 times.
✓ Branch 1 taken 4340661 times.
2226759093 for(int i=0; i<MAXLEVELS; i++)
1992 {
1993 2222418432 count+=(game->lvlitems[i]&liCOMPASS)?1:0;
1994 2222418432 }
1995
1996 4340661 return count;
1997 }
1998
1999 case itype_bosskey:
2000 {
2001 4340661 int count=0;
2002
2003
2/2
✓ Branch 0 taken 2222418432 times.
✓ Branch 1 taken 4340661 times.
2226759093 for(int i=0; i<MAXLEVELS; i++)
2004 {
2005 2222418432 count+=(game->lvlitems[i]&liBOSSKEY)?1:0;
2006 2222418432 }
2007
2008 4340661 return count;
2009 }
2010
2011 default:
2012 113650358 int maxid = current_item_id(item_type, checkmagic, jinx_check, check_bunny);
2013
2014
2/2
✓ Branch 0 taken 81054111 times.
✓ Branch 1 taken 32596247 times.
113650358 if(maxid == -1)
2015 81054111 return 0;
2016
2017 32596247 return itemsbuf[maxid].fam_type;
2018 }
2019 148375646 }
2020
2021 403 std::map<int32_t, int32_t> itemcache;
2022 403 std::map<int32_t, int32_t> itemcache_cost;
2023
2024 void removeFromItemCache(int32_t itemclass)
2025 {
2026 itemcache.erase(itemclass);
2027 itemcache_cost.erase(itemclass);
2028 cache_tile_mod_clear();
2029 }
2030
2031 12921654 void flushItemCache(bool justcost)
2032 {
2033 12921654 itemcache_cost.clear();
2034
2/2
✓ Branch 0 taken 12848680 times.
✓ Branch 1 taken 72974 times.
12921654 if(!justcost)
2035 72974 itemcache.clear();
2036
2/2
✓ Branch 0 taken 6357672 times.
✓ Branch 1 taken 6491008 times.
12848680 else if(replay_version_check(0,19))
2037 6357672 return;
2038
2039 6563982 cache_tile_mod_clear();
2040
2041 //also fix the active subscreen if items were deleted -DD
2042
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6563982 times.
6563982 if(game != NULL)
2043 {
2044 6563982 verifyBothWeapons();
2045 6563982 refresh_subscr_items();
2046 6563982 }
2047 12921654 }
2048
2049 // This is used often, so it should be as direct as possible.
2050 2960350787 int _c_item_id_internal(int itemtype, bool checkmagic, bool jinx_check, bool check_bunny)
2051 {
2052 2960350787 bool use_cost_cache = replay_version_check(19);
2053
2/2
✓ Branch 0 taken 2836997275 times.
✓ Branch 1 taken 123353512 times.
2960350787 if(jinx_check)
2054 {
2055 //special case for shields...
2056
3/4
✓ Branch 0 taken 39671839 times.
✓ Branch 1 taken 83681673 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 39671839 times.
123353512 if (itemtype == itype_shield && !HeroShieldClk())
2057 39671839 jinx_check = false;
2058
4/4
✓ Branch 0 taken 52093442 times.
✓ Branch 1 taken 31588231 times.
✓ Branch 2 taken 10856084 times.
✓ Branch 3 taken 41237358 times.
83681673 else if(!(HeroSwordClk() || HeroItemClk()))
2059 41237358 jinx_check = false; //not jinxed
2060 123353512 }
2061
4/4
✓ Branch 0 taken 114318 times.
✓ Branch 1 taken 2960236469 times.
✓ Branch 2 taken 1853 times.
✓ Branch 3 taken 112465 times.
2960350787 if(!Hero.BunnyClock() || itemtype == itype_pearl) // bunny_check does not apply
2062 2960238322 check_bunny = false;
2063
2/2
✓ Branch 0 taken 2903095960 times.
✓ Branch 1 taken 57254827 times.
2960350787 if(itemtype == itype_ring) checkmagic = true;
2064
4/4
✓ Branch 0 taken 2917906472 times.
✓ Branch 1 taken 42444315 times.
✓ Branch 2 taken 289651715 times.
✓ Branch 3 taken 25153195 times.
3275155697 if (!jinx_check && !check_bunny
2065
4/4
✓ Branch 0 taken 2917821615 times.
✓ Branch 1 taken 84857 times.
✓ Branch 2 taken 314804910 times.
✓ Branch 3 taken 2603016705 times.
2917906472 && (use_cost_cache || itemtype != itype_ring))
2066 {
2067
4/4
✓ Branch 0 taken 556745441 times.
✓ Branch 1 taken 2335922979 times.
✓ Branch 2 taken 246782816 times.
✓ Branch 3 taken 309962625 times.
2892668420 auto& cache = checkmagic && use_cost_cache ? itemcache_cost : itemcache;
2068 2892668420 auto res = cache.find(itemtype);
2069
2070
2/2
✓ Branch 0 taken 2750121064 times.
✓ Branch 1 taken 142547356 times.
2892668420 if(res != cache.end())
2071 2750121064 return res->second;
2072 142547356 }
2073
2074 210229723 int result = -1;
2075 210229723 int highestlevel = -1;
2076
2077
2/2
✓ Branch 0 taken 53818809088 times.
✓ Branch 1 taken 210229723 times.
54029038811 for(int i=0; i<MAXITEMS; i++)
2078 {
2079
6/6
✓ Branch 0 taken 5898561080 times.
✓ Branch 1 taken 47920248008 times.
✓ Branch 2 taken 94723491 times.
✓ Branch 3 taken 5803837589 times.
✓ Branch 4 taken 82048 times.
✓ Branch 5 taken 94641443 times.
53818809088 if(game->get_item(i) && itemsbuf[i].family==itemtype && !item_disabled(i))
2080 {
2081
4/4
✓ Branch 0 taken 90085484 times.
✓ Branch 1 taken 4555959 times.
✓ Branch 2 taken 2473305 times.
✓ Branch 3 taken 87612179 times.
94641443 if(checkmagic && itemtype != itype_magicring)
2082
2/2
✓ Branch 0 taken 87611478 times.
✓ Branch 1 taken 701 times.
87612179 if(!checkmagiccost(i))
2083 701 continue;
2084
6/6
✓ Branch 0 taken 87206289 times.
✓ Branch 1 taken 7434453 times.
✓ Branch 2 taken 1230804 times.
✓ Branch 3 taken 6203649 times.
✓ Branch 4 taken 4007746 times.
✓ Branch 5 taken 3426707 times.
94640742 if(jinx_check && (usesSwordJinx(i) ? HeroSwordClk() : HeroItemClk()))
2085
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3426707 times.
3426707 if(!(itemsbuf[i].flags & item_jinx_immune))
2086 3426707 continue;
2087
3/4
✓ Branch 0 taken 91665 times.
✓ Branch 1 taken 91122370 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 91665 times.
91214035 if(check_bunny && !checkbunny(i))
2088 91665 continue;
2089
2090
2/2
✓ Branch 0 taken 8338981 times.
✓ Branch 1 taken 82783389 times.
91122370 if(itemsbuf[i].fam_type >= highestlevel)
2091 {
2092 82783389 highestlevel = itemsbuf[i].fam_type;
2093 82783389 result=i;
2094 82783389 }
2095 91122370 }
2096 53815290015 }
2097
2098
4/4
✓ Branch 0 taken 167785408 times.
✓ Branch 1 taken 42444315 times.
✓ Branch 2 taken 84857 times.
✓ Branch 3 taken 167700551 times.
210229723 if(!(jinx_check || check_bunny)) //Can't cache jinx_check/check_bunny
2099 {
2100
2/2
✓ Branch 0 taken 125902360 times.
✓ Branch 1 taken 41798191 times.
167700551 if (use_cost_cache)
2101 {
2102
2/2
✓ Branch 0 taken 110287707 times.
✓ Branch 1 taken 15614653 times.
125902360 if (!checkmagic)
2103 15614653 itemcache[itemtype] = result;
2104
6/6
✓ Branch 0 taken 15614653 times.
✓ Branch 1 taken 110287707 times.
✓ Branch 2 taken 677203 times.
✓ Branch 3 taken 14937450 times.
✓ Branch 4 taken 662246 times.
✓ Branch 5 taken 14957 times.
125902360 if (checkmagic || result < 0 || checkmagiccost(result))
2105 125887403 itemcache_cost[itemtype] = result;
2106 125902360 }
2107 else
2108 {
2109 41798191 itemcache[itemtype] = result;
2110 }
2111 167700551 }
2112 210229723 return result;
2113 2960350787 }
2114
2115 // 'jinx_check' indicates that the highest level item *immune to jinxes* should be returned.
2116 2918402730 int current_item_id(int itype, bool checkmagic, bool jinx_check, bool check_bunny)
2117 {
2118
2/4
✓ Branch 0 taken 2918402730 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2918402730 times.
2918402730 if(itype < 0 || itype >= itype_max) return -1;
2119
1/2
✓ Branch 0 taken 2918402730 times.
✗ Branch 1 not taken.
2918402730 if(game->OverrideItems[itype] > -2)
2120 {
2121 auto ovid = game->OverrideItems[itype];
2122 if(ovid < 0 || ovid >= MAXITEMS)
2123 return -1;
2124 if(itemsbuf[ovid].family == itype)
2125 {
2126 if(itype == itype_magicring)
2127 checkmagic = false;
2128 else if(itype == itype_ring)
2129 checkmagic = true;
2130
2131 if(checkmagic && !checkmagiccost(ovid))
2132 return -1;
2133
2134 if (jinx_check && !checkitem_jinx(ovid))
2135 {
2136 return -1;
2137 }
2138 return ovid;
2139 }
2140 }
2141 2918402730 auto ret = _c_item_id_internal(itype,checkmagic,jinx_check,check_bunny);
2142
2/2
✓ Branch 0 taken 81405455 times.
✓ Branch 1 taken 2836997275 times.
2918402730 if(!jinx_check) //If not already a jinx-immune-only check...
2143 {
2144 //And the player IS jinxed...
2145
2/2
✓ Branch 0 taken 2795049218 times.
✓ Branch 1 taken 41948057 times.
2836997275 if(HeroIsJinxed())
2146 {
2147 //Then do a jinx-immune-only check here
2148 41948057 auto ret2 = _c_item_id_internal(itype,checkmagic,true,check_bunny);
2149 //And *IF IT FINDS A VALID ITEM*, return that one instead! -Em
2150 //Should NOT need a compat rule, as this should always return -1 in old quests.
2151
2/2
✓ Branch 0 taken 3161237 times.
✓ Branch 1 taken 38786820 times.
41948057 if(ret2 > -1) return ret2;
2152 38786820 }
2153 2833836038 }
2154 2915241493 return ret;
2155 2918402730 }
2156
2157 65682262 int current_item_power(int itemtype, bool checkmagic, bool jinx_check, bool check_bunny)
2158 {
2159 65682262 int result = current_item_id(itemtype, checkmagic, jinx_check, check_bunny);
2160
2/2
✓ Branch 0 taken 35040930 times.
✓ Branch 1 taken 30641332 times.
65682262 return (result<0) ? 0 : itemsbuf[result].power;
2161 }
2162
2163 25 int32_t heart_container_id()
2164 {
2165
1/2
✓ Branch 0 taken 725 times.
✗ Branch 1 not taken.
725 for(int32_t i=0; i<MAXITEMS; i++)
2166 {
2167
2/2
✓ Branch 0 taken 25 times.
✓ Branch 1 taken 700 times.
725 if(itemsbuf[i].family == itype_heartcontainer)
2168 {
2169 25 return i;
2170 }
2171 700 }
2172 return -1;
2173 25 }
2174
2175 struct tilemod_cache_state_t
2176 {
2177
6/6
✓ Branch 0 taken 4340305 times.
✓ Branch 1 taken 8516871 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 8516869 times.
✓ Branch 4 taken 354 times.
✓ Branch 5 taken 8516515 times.
21374047 bool operator==(const tilemod_cache_state_t&) const = default;
2178
2179 bool valid;
2180 bool bunny_clock;
2181 bool superman;
2182 int shield;
2183 };
2184 tilemod_cache_state_t tilemod_cache_state;
2185 int32_t tilemod_cache_value;
2186
2187 6565500 void cache_tile_mod_clear()
2188 {
2189 6565500 tilemod_cache_state = {false};
2190 6565500 }
2191
2192 12857176 int32_t item_tile_mod()
2193 {
2194 51428704 tilemod_cache_state_t state = {
2195 .valid = true,
2196 12857176 .bunny_clock = Hero.BunnyClock() != 0,
2197 12857176 .superman = Hero.superman,
2198 12857176 .shield = Hero.active_shield_id,
2199 };
2200
2/2
✓ Branch 0 taken 8516515 times.
✓ Branch 1 taken 4340661 times.
12857176 if (tilemod_cache_state == state)
2201 8516515 return tilemod_cache_value;
2202
2203 4340661 int32_t tile=0;
2204 4340661 bool check_bombcost = !get_qr(qr_BROKEN_BOMB_AMMO_COSTS);
2205
4/4
✓ Branch 0 taken 3927424 times.
✓ Branch 1 taken 413237 times.
✓ Branch 2 taken 2998637 times.
✓ Branch 3 taken 928787 times.
4340661 if(check_bombcost || game->get_bombs())
2206 {
2207 3411874 int32_t itemid = current_item_id(itype_bomb,check_bombcost);
2208
3/4
✓ Branch 0 taken 3352359 times.
✓ Branch 1 taken 59515 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3352359 times.
3411874 if(itemid > -1 && checkbunny(itemid))
2209 3352359 tile+=itemsbuf[itemid].ltm;
2210 3411874 }
2211
2212
4/4
✓ Branch 0 taken 3927424 times.
✓ Branch 1 taken 413237 times.
✓ Branch 2 taken 965298 times.
✓ Branch 3 taken 2962126 times.
4340661 if(check_bombcost || game->get_sbombs())
2213 {
2214 1378535 int32_t itemid = current_item_id(itype_sbomb,check_bombcost);
2215
3/4
✓ Branch 0 taken 965057 times.
✓ Branch 1 taken 413478 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 965057 times.
1378535 if(itemid > -1 && checkbunny(itemid))
2216 965057 tile+=itemsbuf[itemid].ltm;
2217 1378535 }
2218
2219
2/2
✓ Branch 0 taken 4328748 times.
✓ Branch 1 taken 11913 times.
4340661 if(current_item(itype_clock))
2220 {
2221 11913 int32_t itemid =
2222
2/2
✓ Branch 0 taken 11881 times.
✓ Branch 1 taken 32 times.
11913 get_qr(qr_HARDCODED_LITEM_LTMS)
2223 ? iClock
2224 32 : getHighestLevelEvenUnowned(itemsbuf, itype_clock);
2225
2/4
✓ Branch 0 taken 11913 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 11913 times.
11913 if(itemid > -1 && checkbunny(itemid))
2226 11913 tile+=itemsbuf[itemid].ltm;
2227 11913 }
2228
2229
2/2
✓ Branch 0 taken 3755263 times.
✓ Branch 1 taken 585398 times.
4340661 if(current_item(itype_key))
2230 {
2231 585398 int32_t itemid =
2232
2/2
✓ Branch 0 taken 548396 times.
✓ Branch 1 taken 37002 times.
585398 get_qr(qr_HARDCODED_LITEM_LTMS)
2233 ? iKey
2234 37002 : getHighestLevelEvenUnowned(itemsbuf, itype_key);
2235
2/4
✓ Branch 0 taken 585398 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 585398 times.
585398 if(itemid > -1 && checkbunny(itemid))
2236 585398 tile+=itemsbuf[itemid].ltm;
2237 585398 }
2238
2239
2/2
✓ Branch 0 taken 3839778 times.
✓ Branch 1 taken 500883 times.
4340661 if(current_item(itype_lkey))
2240 {
2241 500883 int32_t itemid =
2242
2/2
✓ Branch 0 taken 414169 times.
✓ Branch 1 taken 86714 times.
500883 get_qr(qr_HARDCODED_LITEM_LTMS)
2243 ? iLevelKey
2244 86714 : getHighestLevelEvenUnowned(itemsbuf, itype_lkey);
2245
2/4
✓ Branch 0 taken 500883 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 500883 times.
500883 if(itemid > -1 && checkbunny(itemid))
2246 500883 tile+=itemsbuf[itemid].ltm;
2247 500883 }
2248
2249
2/2
✓ Branch 0 taken 1586384 times.
✓ Branch 1 taken 2754277 times.
4340661 if(current_item(itype_map))
2250 {
2251 2754277 int32_t itemid =
2252
2/2
✓ Branch 0 taken 2743281 times.
✓ Branch 1 taken 10996 times.
2754277 get_qr(qr_HARDCODED_LITEM_LTMS)
2253 ? iMap
2254 10996 : getHighestLevelEvenUnowned(itemsbuf, itype_map);
2255
2/4
✓ Branch 0 taken 2754277 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2754277 times.
2754277 if(itemid > -1 && checkbunny(itemid))
2256 2754277 tile+=itemsbuf[itemid].ltm;
2257 2754277 }
2258
2259
2/2
✓ Branch 0 taken 2028672 times.
✓ Branch 1 taken 2311989 times.
4340661 if(current_item(itype_compass))
2260 {
2261 2311989 int32_t itemid =
2262
2/2
✓ Branch 0 taken 2295941 times.
✓ Branch 1 taken 16048 times.
2311989 get_qr(qr_HARDCODED_LITEM_LTMS)
2263 ? iCompass
2264 16048 : getHighestLevelEvenUnowned(itemsbuf, itype_compass);
2265
2/4
✓ Branch 0 taken 2311989 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2311989 times.
2311989 if(itemid > -1 && checkbunny(itemid))
2266 2311989 tile+=itemsbuf[itemid].ltm;
2267 2311989 }
2268
2269
2/2
✓ Branch 0 taken 1254245 times.
✓ Branch 1 taken 3086416 times.
4340661 if(current_item(itype_bosskey))
2270 {
2271 3086416 int32_t itemid =
2272
2/2
✓ Branch 0 taken 2993139 times.
✓ Branch 1 taken 93277 times.
3086416 get_qr(qr_HARDCODED_LITEM_LTMS)
2273 ? iBossKey
2274 93277 : getHighestLevelEvenUnowned(itemsbuf, itype_bosskey);
2275
2/4
✓ Branch 0 taken 3086416 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 3086416 times.
3086416 if(itemid > -1 && checkbunny(itemid))
2276 3086416 tile+=itemsbuf[itemid].ltm;
2277 3086416 }
2278
2279
2/2
✓ Branch 0 taken 48277 times.
✓ Branch 1 taken 4292384 times.
4340661 if(current_item(itype_magiccontainer))
2280 {
2281 4292384 int32_t itemid =
2282
2/2
✓ Branch 0 taken 3823787 times.
✓ Branch 1 taken 468597 times.
4292384 get_qr(qr_HARDCODED_LITEM_LTMS)
2283 ? iMagicC
2284 468597 : getHighestLevelEvenUnowned(itemsbuf, itype_magiccontainer);
2285
3/4
✓ Branch 0 taken 4292384 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 17 times.
✓ Branch 3 taken 4292367 times.
4292384 if(itemid > -1 && checkbunny(itemid))
2286 4292367 tile+=itemsbuf[itemid].ltm;
2287 4292384 }
2288
2289
2/2
✓ Branch 0 taken 1314734 times.
✓ Branch 1 taken 3025927 times.
4340661 if(current_item(itype_triforcepiece))
2290 {
2291 3025927 int32_t itemid =
2292
2/2
✓ Branch 0 taken 2988925 times.
✓ Branch 1 taken 37002 times.
3025927 get_qr(qr_HARDCODED_LITEM_LTMS)
2293 ? iTriforce
2294 37002 : getHighestLevelEvenUnowned(itemsbuf, itype_triforcepiece);
2295
2/4
✓ Branch 0 taken 3025927 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 3025927 times.
3025927 if(itemid > -1 && checkbunny(itemid))
2296 3025927 tile+=itemsbuf[itemid].ltm;
2297 3025927 }
2298
2299
2/2
✓ Branch 0 taken 2222418432 times.
✓ Branch 1 taken 4340661 times.
2226759093 for(int32_t i=0; i<itype_max; i++)
2300 {
2301
2/2
✓ Branch 0 taken 1982385664 times.
✓ Branch 1 taken 240032768 times.
2222418432 if(!get_qr(qr_HARDCODED_LITEM_LTMS))
2302 {
2303
2/2
✓ Branch 0 taken 4688140 times.
✓ Branch 1 taken 235344628 times.
240032768 switch(i)
2304 {
2305 case itype_bomb:
2306 case itype_sbomb:
2307 case itype_clock:
2308 case itype_key:
2309 case itype_lkey:
2310 case itype_map:
2311 case itype_compass:
2312 case itype_bosskey:
2313 case itype_magiccontainer:
2314 case itype_triforcepiece:
2315 4688140 continue; //already handled
2316 }
2317 235344628 }
2318 2217730292 int32_t itemid = current_item_id(i,false);
2319
2/2
✓ Branch 0 taken 2213389631 times.
✓ Branch 1 taken 4340661 times.
2217730292 if(i == itype_shield)
2320 4340661 itemid = getCurrentShield(false);
2321
2322
4/4
✓ Branch 0 taken 114158184 times.
✓ Branch 1 taken 2103572108 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 114158183 times.
2217730292 if(itemid < 0 || !checkbunny(itemid))
2323 2103572109 continue;
2324
2325 114158183 itemdata const& itm = itemsbuf[itemid];
2326
2327
2/2
✓ Branch 0 taken 110538050 times.
✓ Branch 1 taken 3620133 times.
114158183 switch(itm.family)
2328 {
2329 case itype_shield:
2330
1/2
✓ Branch 0 taken 3620133 times.
✗ Branch 1 not taken.
3620133 if(itm.flags & item_flag9) //active shield
2331 {
2332 if(!usingActiveShield(itemid))
2333 {
2334 tile+=itm.misc6; //'Inactive PTM'
2335 continue;
2336 }
2337 }
2338 3620133 break;
2339 }
2340
2341 114158183 tile+=itm.ltm;
2342 114158183 }
2343
2344 4340661 tilemod_cache_value = tile;
2345 4340661 tilemod_cache_state = state;
2346 4340661 return tile;
2347 12857176 }
2348
2349 12857176 int32_t bunny_tile_mod()
2350 {
2351
2/2
✓ Branch 0 taken 1870 times.
✓ Branch 1 taken 12855306 times.
12857176 if(Hero.BunnyClock())
2352 {
2353 1870 return game->get_bunny_ltm();
2354 }
2355 12855306 return 0;
2356 12857176 }
2357
2358 // Hints are drawn on a separate layer to combo reveals.
2359 // TODO: move out of zc_sys.cpp, weird place for this code.
2360 20058 void draw_lens_under(BITMAP *dest, bool layer)
2361 {
2362 //Lens flag 1: Replacement for qr_LENSHINTS; if set, lens will show hints. Does nothing if flag 2 is set.
2363 //Lens flag 2: Disable "hints", prevent rendering of Secret Combos
2364 //Lens flag 3: Don't show armos/chest/dive items
2365 //Lens flag 4: Show Raft Paths
2366 //Lens flag 5: Show Invisible Enemies
2367
4/4
✓ Branch 0 taken 19602 times.
✓ Branch 1 taken 456 times.
✓ Branch 2 taken 9801 times.
✓ Branch 3 taken 9801 times.
20058 bool hints = (itemsbuf[Hero.getLastLensID()].flags & item_flag2) ? false : (layer && (itemsbuf[Hero.getLastLensID()].flags & item_flag1));
2368
2369 20058 int32_t strike_hint_table[11]=
2370 {
2371 mfARROW, mfBOMB, mfBRANG, mfWANDMAGIC,
2372 mfSWORD, mfREFMAGIC, mfHOOKSHOT,
2373 mfREFFIREBALL, mfHAMMER, mfSWORDBEAM, mfWAND
2374 };
2375
2376 {
2377 20058 int32_t blink_rate=flash_reduction_enabled()?6:1;
2378 20058 int32_t tempitem, tempweapon=0;
2379 20058 strike_hint=strike_hint_table[strike_hint_counter];
2380
2381
2/2
✓ Branch 0 taken 19459 times.
✓ Branch 1 taken 599 times.
20058 if(strike_hint_timer>32)
2382 {
2383 599 strike_hint_timer=0;
2384 599 strike_hint_counter=((strike_hint_counter+1)%11);
2385 599 }
2386
2387 20058 ++strike_hint_timer;
2388
2389 3550266 for_every_visible_rpos_layer0([&](const rpos_handle_t& rpos_handle) {
2390 3530208 mapscr* scr = rpos_handle.scr;
2391 7306676 auto [x, y] = rpos_handle.xy();
2392 7060416 y += playing_field_offset;
2393
2394 3530208 int32_t tempitemx=-16, tempitemy=-16;
2395 3530208 int32_t tempweaponx=-16, tempweapony=-16;
2396
2397
2/2
✓ Branch 0 taken 7060416 times.
✓ Branch 1 taken 3530208 times.
10590624 for(int32_t iter=0; iter<2; ++iter)
2398 {
2399 7060416 int32_t checkflag=0;
2400
2401
2/2
✓ Branch 0 taken 3530208 times.
✓ Branch 1 taken 3530208 times.
7060416 if(iter==0)
2402 {
2403 3530208 checkflag = rpos_handle.cflag();
2404 3530208 }
2405 else
2406 {
2407 3530208 checkflag = rpos_handle.sflag();
2408 }
2409
2410
2/2
✓ Branch 0 taken 7059318 times.
✓ Branch 1 taken 1098 times.
7060416 if(checkflag==mfSTRIKE)
2411 {
2412
2/2
✓ Branch 0 taken 192 times.
✓ Branch 1 taken 906 times.
1098 if(!hints)
2413 {
2414
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 906 times.
906 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sSTRIKE],scr->secretcset[sSTRIKE]);
2415 906 }
2416 else
2417 {
2418 192 checkflag = strike_hint;
2419 }
2420 1098 }
2421
2422
21/36
✓ Branch 0 taken 6911766 times.
✓ Branch 1 taken 3258 times.
✓ Branch 2 taken 108898 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2602 times.
✓ Branch 5 taken 28750 times.
✓ Branch 6 taken 2418 times.
✓ Branch 7 taken 504 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✓ Branch 11 taken 814 times.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✓ Branch 14 taken 93 times.
✓ Branch 15 taken 96 times.
✓ Branch 16 taken 24 times.
✓ Branch 17 taken 25 times.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✓ Branch 20 taken 138 times.
✓ Branch 21 taken 16 times.
✓ Branch 22 taken 16 times.
✓ Branch 23 taken 7 times.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✓ Branch 27 taken 16 times.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
✓ Branch 31 taken 17 times.
✓ Branch 32 taken 35 times.
✓ Branch 33 taken 17 times.
✗ Branch 34 not taken.
✓ Branch 35 taken 906 times.
7060416 switch(checkflag)
2423 {
2424 case 0:
2425 case mfZELDA:
2426 case mfPUSHED:
2427 case mfENEMY0:
2428 case mfENEMY1:
2429 case mfENEMY2:
2430 case mfENEMY3:
2431 case mfENEMY4:
2432 case mfENEMY5:
2433 case mfENEMY6:
2434 case mfENEMY7:
2435 case mfENEMY8:
2436 case mfENEMY9:
2437 case mfSINGLE:
2438 case mfSINGLE16:
2439 case mfNOENEMY:
2440 case mfTRAP_H:
2441 case mfTRAP_V:
2442 case mfTRAP_4:
2443 case mfTRAP_LR:
2444 case mfTRAP_UD:
2445 case mfNOGROUNDENEMY:
2446 case mfNOBLOCKS:
2447 case mfSCRIPT1:
2448 case mfSCRIPT2:
2449 case mfSCRIPT3:
2450 case mfSCRIPT4:
2451 case mfSCRIPT5:
2452 case mfSCRIPT6:
2453 case mfSCRIPT7:
2454 case mfSCRIPT8:
2455 case mfSCRIPT9:
2456 case mfSCRIPT10:
2457 case mfSCRIPT11:
2458 case mfSCRIPT12:
2459 case mfSCRIPT13:
2460 case mfSCRIPT14:
2461 case mfSCRIPT15:
2462 case mfSCRIPT16:
2463 case mfSCRIPT17:
2464 case mfSCRIPT18:
2465 case mfSCRIPT19:
2466 case mfSCRIPT20:
2467 case mfPITHOLE:
2468 case mfPITFALLFLOOR:
2469 case mfLAVA:
2470 case mfICE:
2471 case mfICEDAMAGE:
2472 case mfDAMAGE1:
2473 case mfDAMAGE2:
2474 case mfDAMAGE4:
2475 case mfDAMAGE8:
2476 case mfDAMAGE16:
2477 case mfDAMAGE32:
2478 case mfFREEZEALL:
2479 case mfFREZEALLANSFFCS:
2480 case mfFREEZEFFCSOLY:
2481 case mfSCRITPTW1TRIG:
2482 case mfSCRITPTW2TRIG:
2483 case mfSCRITPTW3TRIG:
2484 case mfSCRITPTW4TRIG:
2485 case mfSCRITPTW5TRIG:
2486 case mfSCRITPTW6TRIG:
2487 case mfSCRITPTW7TRIG:
2488 case mfSCRITPTW8TRIG:
2489 case mfSCRITPTW9TRIG:
2490 case mfSCRITPTW10TRIG:
2491 case mfTROWEL:
2492 case mfTROWELNEXT:
2493 case mfTROWELSPECIALITEM:
2494 case mfSLASHPOT:
2495 case mfLIFTPOT:
2496 case mfLIFTORSLASH:
2497 case mfLIFTROCK:
2498 case mfLIFTROCKHEAVY:
2499 case mfDROPITEM:
2500 case mfSPECIALITEM:
2501 case mfDROPKEY:
2502 case mfDROPLKEY:
2503 case mfDROPCOMPASS:
2504 case mfDROPMAP:
2505 case mfDROPBOSSKEY:
2506 case mfSPAWNNPC:
2507 case mfSWITCHHOOK:
2508 case mfSIDEVIEWLADDER:
2509 case mfSIDEVIEWPLATFORM:
2510 case mfNOENEMYSPAWN:
2511 case mfENEMYALL:
2512 case mfNOMIRROR:
2513 case mfUNSAFEGROUND:
2514 case mf168:
2515 case mf169:
2516 case mf170:
2517 case mf171:
2518 case mf172:
2519 case mf173:
2520 case mf174:
2521 case mf175:
2522 case mf176:
2523 case mf177:
2524 case mf178:
2525 case mf179:
2526 case mf180:
2527 case mf181:
2528 case mf182:
2529 case mf183:
2530 case mf184:
2531 case mf185:
2532 case mf186:
2533 case mf187:
2534 case mf188:
2535 case mf189:
2536 case mf190:
2537 case mf191:
2538 case mf192:
2539 case mf193:
2540 case mf194:
2541 case mf195:
2542 case mf196:
2543 case mf197:
2544 case mf198:
2545 case mf199:
2546 case mf200:
2547 case mf201:
2548 case mf202:
2549 case mf203:
2550 case mf204:
2551 case mf205:
2552 case mf206:
2553 case mf207:
2554 case mf208:
2555 case mf209:
2556 case mf210:
2557 case mf211:
2558 case mf212:
2559 case mf213:
2560 case mf214:
2561 case mf215:
2562 case mf216:
2563 case mf217:
2564 case mf218:
2565 case mf219:
2566 case mf220:
2567 case mf221:
2568 case mf222:
2569 case mf223:
2570 case mf224:
2571 case mf225:
2572 case mf226:
2573 case mf227:
2574 case mf228:
2575 case mf229:
2576 case mf230:
2577 case mf231:
2578 case mf232:
2579 case mf233:
2580 case mf234:
2581 case mf235:
2582 case mf236:
2583 case mf237:
2584 case mf238:
2585 case mf239:
2586 case mf240:
2587 case mf241:
2588 case mf242:
2589 case mf243:
2590 case mf244:
2591 case mf245:
2592 case mf246:
2593 case mf247:
2594 case mf248:
2595 case mf249:
2596 case mf250:
2597 case mf251:
2598 case mf252:
2599 case mf253:
2600 case mf254:
2601 case mfEXTENDED:
2602 6911766 break;
2603
2604 case mfPUSHUD:
2605 case mfPUSHLR:
2606 case mfPUSH4:
2607 case mfPUSHU:
2608 case mfPUSHD:
2609 case mfPUSHL:
2610 case mfPUSHR:
2611 case mfPUSHUDNS:
2612 case mfPUSHLRNS:
2613 case mfPUSH4NS:
2614 case mfPUSHUNS:
2615 case mfPUSHDNS:
2616 case mfPUSHLNS:
2617 case mfPUSHRNS:
2618 case mfPUSHUDINS:
2619 case mfPUSHLRINS:
2620 case mfPUSH4INS:
2621 case mfPUSHUINS:
2622 case mfPUSHDINS:
2623 case mfPUSHLINS:
2624 case mfPUSHRINS:
2625
3/4
✓ Branch 0 taken 1939 times.
✓ Branch 1 taken 1319 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1939 times.
3258 if(!hints && ((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&16))
2626
2/6
✗ Branch 0 not taken.
✓ Branch 1 taken 1939 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1939 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
1939 || ((get_debug() && zc_getkey(KEY_N)) && (frame&16))))
2627 {
2628 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->undercombo,scr->undercset);
2629 }
2630
2631
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3258 times.
3258 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2632
3/6
✓ Branch 0 taken 2520 times.
✓ Branch 1 taken 738 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 738 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
3258 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2633 {
2634
2/2
✓ Branch 0 taken 1488 times.
✓ Branch 1 taken 1032 times.
2520 if(hints)
2635 {
2636
3/3
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 63 times.
✓ Branch 2 taken 897 times.
1032 switch (rpos_handle.ctype())
2637 {
2638 case cPUSH_HEAVY:
2639 case cPUSH_HW:
2640 72 tempitem=getItemIDPower(itemsbuf,itype_bracelet,1);
2641 144 tempitemx=x, tempitemy=y;
2642
2643
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(tempitem>-1)
2644 72 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2645
2646 72 break;
2647
2648 case cPUSH_HEAVY2:
2649 case cPUSH_HW2:
2650 63 tempitem=getItemIDPower(itemsbuf,itype_bracelet,2);
2651 126 tempitemx=x, tempitemy=y;
2652
2653
1/2
✓ Branch 0 taken 63 times.
✗ Branch 1 not taken.
63 if(tempitem>-1)
2654 63 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2655
2656 63 break;
2657 }
2658 1032 }
2659 2520 }
2660
2661 3258 break;
2662
2663 case mfWHISTLE:
2664
1/2
✓ Branch 0 taken 2418 times.
✗ Branch 1 not taken.
2418 if(hints)
2665 {
2666 tempitem=getItemID(itemsbuf,itype_whistle,1);
2667
2668 if(tempitem<0) break;
2669
2670 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2671 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2672 {
2673 tempitemx=x;
2674 tempitemy=y;
2675 }
2676
2677 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2678 }
2679
2680 2418 break;
2681
2682 //Why is this here?
2683 case mfFAIRY:
2684 case mfMAGICFAIRY:
2685 case mfALLFAIRY:
2686 if(hints)
2687 {
2688 tempitem=getItemID(itemsbuf, itype_fairy,1);//iFairyMoving;
2689
2690 if(tempitem < 0) break;
2691
2692 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2693 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2694 {
2695 tempitemx=x;
2696 tempitemy=y;
2697 }
2698
2699 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2700 }
2701
2702 break;
2703
2704 case mfANYFIRE:
2705
2/2
✓ Branch 0 taken 252 times.
✓ Branch 1 taken 252 times.
504 if(!hints)
2706 {
2707
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 252 times.
252 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sBCANDLE],scr->secretcset[sBCANDLE]);
2708 252 }
2709 else
2710 {
2711 252 tempitem=getItemID(itemsbuf,itype_candle,1);
2712
2713
1/2
✓ Branch 0 taken 252 times.
✗ Branch 1 not taken.
252 if(tempitem<0) break;
2714
2715
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 252 times.
252 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2716
3/6
✓ Branch 0 taken 189 times.
✓ Branch 1 taken 63 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 63 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
252 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2717 {
2718 189 tempitemx=x;
2719 189 tempitemy=y;
2720 189 }
2721
2722 252 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2723 }
2724
2725 504 break;
2726
2727 case mfSTRONGFIRE:
2728 if(!hints)
2729 {
2730 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sRCANDLE],scr->secretcset[sRCANDLE]);
2731 }
2732 else
2733 {
2734 tempitem=getItemID(itemsbuf,itype_candle,2);
2735
2736 if(tempitem<0) break;
2737
2738 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2739 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2740 {
2741 tempitemx=x;
2742 tempitemy=y;
2743 }
2744
2745 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2746 }
2747
2748 break;
2749
2750 case mfMAGICFIRE:
2751 if(!hints)
2752 {
2753 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sWANDFIRE],scr->secretcset[sWANDFIRE]);
2754 }
2755 else
2756 {
2757 tempitem=getItemID(itemsbuf,itype_wand,1);
2758
2759 if(tempitem<0) break;
2760
2761 tempweapon=wFire;
2762
2763 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2764 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2765 {
2766 tempitemx=x;
2767 tempitemy=y;
2768 }
2769 else
2770 {
2771 tempweaponx=x;
2772 tempweapony=y;
2773 }
2774
2775 putweapon(dest,tempweaponx,tempweapony,tempweapon, 0, up, lens_hint_weapon[tempweapon][0], lens_hint_weapon[tempweapon][1],-1);
2776 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2777 }
2778
2779 break;
2780
2781 case mfDIVINEFIRE:
2782 if(!hints)
2783 {
2784 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sDIVINEFIRE],scr->secretcset[sDIVINEFIRE]);
2785 }
2786 else
2787 {
2788 tempitem=getItemID(itemsbuf,itype_divinefire,1);
2789
2790 if(tempitem<0) break;
2791
2792 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2793 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2794 {
2795 tempitemx=x;
2796 tempitemy=y;
2797 }
2798
2799 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2800 }
2801
2802 break;
2803
2804 case mfARROW:
2805
2/2
✓ Branch 0 taken 82 times.
✓ Branch 1 taken 732 times.
814 if(!hints)
2806 {
2807
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 732 times.
732 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sARROW],scr->secretcset[sARROW]);
2808 732 }
2809 else
2810 {
2811 82 tempitem=getItemID(itemsbuf,itype_arrow,1);
2812
2813
1/2
✓ Branch 0 taken 82 times.
✗ Branch 1 not taken.
82 if(tempitem<0) break;
2814
2815
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 82 times.
82 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2816
3/6
✓ Branch 0 taken 61 times.
✓ Branch 1 taken 21 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 21 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
82 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2817 {
2818 61 tempitemx=x;
2819 61 tempitemy=y;
2820 61 }
2821
2822 82 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2823 }
2824
2825 814 break;
2826
2827 case mfSARROW:
2828 if(!hints)
2829 {
2830 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sSARROW],scr->secretcset[sSARROW]);
2831 }
2832 else
2833 {
2834 tempitem=getItemID(itemsbuf,itype_arrow,2);
2835
2836 if(tempitem<0) break;
2837
2838 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2839 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2840 {
2841 tempitemx=x;
2842 tempitemy=y;
2843 }
2844
2845 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2846 }
2847
2848 break;
2849
2850 case mfGARROW:
2851 if(!hints)
2852 {
2853 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sGARROW],scr->secretcset[sGARROW]);
2854 }
2855 else
2856 {
2857 tempitem=getItemID(itemsbuf,itype_arrow,3);
2858
2859 if(tempitem<0) break;
2860
2861 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2862 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2863 {
2864 tempitemx=x;
2865 tempitemy=y;
2866 }
2867
2868 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2869 }
2870
2871 break;
2872
2873 case mfBOMB:
2874
2/2
✓ Branch 0 taken 17 times.
✓ Branch 1 taken 76 times.
93 if(!hints)
2875 {
2876
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 76 times.
76 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sBOMB],scr->secretcset[sBOMB]);
2877 76 }
2878 else
2879 {
2880 //tempitem=getItemID(itemsbuf,itype_bomb,1);
2881 17 tempweapon = wLitBomb;
2882
2883 //if (tempitem<0) break;
2884
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 17 times.
17 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2885
3/6
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 5 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
17 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2886 {
2887 12 tempweaponx=x;
2888 12 tempweapony=y;
2889 12 }
2890
2891 17 putweapon(dest,tempweaponx,tempweapony+lens_hint_weapon[tempweapon][4],tempweapon, 0, up, lens_hint_weapon[tempweapon][0], lens_hint_weapon[tempweapon][1],-1);
2892 }
2893
2894 93 break;
2895
2896 case mfSBOMB:
2897
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 48 times.
96 if(!hints)
2898 {
2899
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 48 times.
48 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sSBOMB],scr->secretcset[sSBOMB]);
2900 48 }
2901 else
2902 {
2903 //tempitem=getItemID(itemsbuf,itype_sbomb,1);
2904 //if (tempitem<0) break;
2905 48 tempweapon = wLitSBomb;
2906
2907
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 48 times.
48 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2908
3/6
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 12 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
48 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2909 {
2910 36 tempweaponx=x;
2911 36 tempweapony=y;
2912 36 }
2913
2914 48 putweapon(dest,tempweaponx,tempweapony+lens_hint_weapon[tempweapon][4],tempweapon, 0, up, lens_hint_weapon[tempweapon][0], lens_hint_weapon[tempweapon][1],-1);
2915 }
2916
2917 96 break;
2918
2919 case mfARMOS_SECRET:
2920
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 12 times.
24 if(!hints)
2921 {
2922
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))
2923 36 putcombo(dest,x,y,scr->secretcombo[sSTAIRS],scr->secretcset[sSTAIRS]);
2924 12 }
2925 24 break;
2926
2927 case mfBRANG:
2928
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 20 times.
25 if(!hints)
2929 {
2930
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 20 times.
20 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))
2931 60 putcombo(dest,x,y,scr->secretcombo[sBRANG],scr->secretcset[sBRANG]);
2932 20 }
2933 else
2934 {
2935 5 tempitem=getItemID(itemsbuf,itype_brang,1);
2936
2937
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 if(tempitem<0) break;
2938
2939
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
5 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2940
3/6
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
5 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2941 {
2942 4 tempitemx=x;
2943 4 tempitemy=y;
2944 4 }
2945
2946 5 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2947 }
2948
2949 25 break;
2950
2951 case mfMBRANG:
2952 if(!hints)
2953 {
2954 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sMBRANG],scr->secretcset[sMBRANG]);
2955 }
2956 else
2957 {
2958 tempitem=getItemID(itemsbuf,itype_brang,2);
2959
2960 if(tempitem<0) break;
2961
2962 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2963 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2964 {
2965 tempitemx=x;
2966 tempitemy=y;
2967 }
2968
2969 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2970 }
2971
2972 break;
2973
2974 case mfFBRANG:
2975 if(!hints)
2976 {
2977 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sFBRANG],scr->secretcset[sFBRANG]);
2978 }
2979 else
2980 {
2981 tempitem=getItemID(itemsbuf,itype_brang,3);
2982
2983 if(tempitem<0) break;
2984
2985 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2986 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2987 {
2988 tempitemx=x;
2989 tempitemy=y;
2990 }
2991
2992 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2993 }
2994
2995 break;
2996
2997 case mfWANDMAGIC:
2998
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 138 times.
138 if(!hints)
2999 {
3000
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 138 times.
138 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sWANDMAGIC],scr->secretcset[sWANDMAGIC]);
3001 138 }
3002 else
3003 {
3004 tempitem=getItemID(itemsbuf,itype_wand,1);
3005
3006 if(tempitem<0) break;
3007
3008 tempweapon=itemsbuf[tempitem].wpn3;
3009
3010 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3011 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3012 {
3013 tempitemx=x;
3014 tempitemy=y;
3015 }
3016 else
3017 {
3018 tempweaponx=x;
3019 tempweapony=y;
3020 --lens_hint_weapon[wMagic][4];
3021
3022 if(lens_hint_weapon[wMagic][4]<-8)
3023 {
3024 lens_hint_weapon[wMagic][4]=8;
3025 }
3026 }
3027
3028 putweapon(dest,tempweaponx,tempweapony+lens_hint_weapon[tempweapon][4],tempweapon, 0, up, lens_hint_weapon[tempweapon][0], lens_hint_weapon[tempweapon][1],-1);
3029 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3030 }
3031
3032 138 break;
3033
3034 case mfREFMAGIC:
3035
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(!hints)
3036 {
3037 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sREFMAGIC],scr->secretcset[sREFMAGIC]);
3038 }
3039 else
3040 {
3041 16 tempitem=getItemID(itemsbuf,itype_shield,3);
3042
3043
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(tempitem<0) break;
3044
3045 16 tempweapon=ewMagic;
3046
3047
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
16 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3048
3/6
✓ Branch 0 taken 13 times.
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
16 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3049 {
3050 13 tempitemx=x;
3051 13 tempitemy=y;
3052 13 }
3053 else
3054 {
3055 3 tempweaponx=x;
3056 3 tempweapony=y;
3057
3058
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
3 if(lens_hint_weapon[ewMagic][2]==up)
3059 {
3060 1 --lens_hint_weapon[ewMagic][4];
3061 1 }
3062 else
3063 {
3064 2 ++lens_hint_weapon[ewMagic][4];
3065 }
3066
3067
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if(lens_hint_weapon[ewMagic][4]>8)
3068 {
3069 lens_hint_weapon[ewMagic][2]=up;
3070 }
3071
3072
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2 times.
3 if(lens_hint_weapon[ewMagic][4]<=0)
3073 {
3074 2 lens_hint_weapon[ewMagic][2]=down;
3075 2 }
3076 }
3077
3078 16 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3079 16 putweapon(dest,tempweaponx,tempweapony+lens_hint_weapon[tempweapon][4],tempweapon, 0, lens_hint_weapon[ewMagic][2], lens_hint_weapon[tempweapon][0], lens_hint_weapon[tempweapon][1],-1);
3080 }
3081
3082 16 break;
3083
3084 case mfREFFIREBALL:
3085
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(!hints)
3086 {
3087 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sREFFIREBALL],scr->secretcset[sREFFIREBALL]);
3088 }
3089 else
3090 {
3091 16 tempitem=getItemID(itemsbuf,itype_shield,3);
3092
3093
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(tempitem<0) break;
3094
3095 16 tempweapon=ewFireball;
3096
3097
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
16 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3098
3/6
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 4 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
16 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3099 {
3100 12 tempitemx=x;
3101 12 tempitemy=y;
3102 12 tempweaponx=x;
3103 12 tempweapony=y;
3104 12 ++lens_hint_weapon[ewFireball][3];
3105
3106
2/2
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 1 times.
12 if(lens_hint_weapon[ewFireball][3]>8)
3107 {
3108 1 lens_hint_weapon[ewFireball][3]=-8;
3109 1 lens_hint_weapon[ewFireball][4]=8;
3110 1 }
3111
3112
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 4 times.
12 if(lens_hint_weapon[ewFireball][3]>0)
3113 {
3114 8 ++lens_hint_weapon[ewFireball][4];
3115 8 }
3116 else
3117 {
3118 4 --lens_hint_weapon[ewFireball][4];
3119 }
3120 12 }
3121
3122 16 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3123 16 putweapon(dest,tempweaponx+lens_hint_weapon[tempweapon][3],tempweapony+lens_hint_weapon[ewFireball][4],tempweapon, 0, up, lens_hint_weapon[tempweapon][0], lens_hint_weapon[tempweapon][1],-1);
3124 }
3125
3126 16 break;
3127
3128 case mfSWORD:
3129
1/2
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
7 if(!hints)
3130 {
3131 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sSWORD],scr->secretcset[sSWORD]);
3132 }
3133 else
3134 {
3135 7 tempitem=getItemID(itemsbuf,itype_sword,1);
3136
3137
1/2
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
7 if(tempitem<0) break;
3138
3139
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7 times.
7 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3140
3/6
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
7 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3141 {
3142 5 tempitemx=x;
3143 5 tempitemy=y;
3144 5 }
3145
3146 7 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3147 }
3148
3149 7 break;
3150
3151 case mfWSWORD:
3152 if(!hints)
3153 {
3154 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sWSWORD],scr->secretcset[sWSWORD]);
3155 }
3156 else
3157 {
3158 tempitem=getItemID(itemsbuf,itype_sword,2);
3159
3160 if(tempitem<0) break;
3161
3162 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3163 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3164 {
3165 tempitemx=x;
3166 tempitemy=y;
3167 }
3168
3169 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3170 }
3171
3172 break;
3173
3174 case mfMSWORD:
3175 if(!hints)
3176 {
3177 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sMSWORD],scr->secretcset[sMSWORD]);
3178 }
3179 else
3180 {
3181 tempitem=getItemID(itemsbuf,itype_sword,3);
3182
3183 if(tempitem<0) break;
3184
3185 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3186 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3187 {
3188 tempitemx=x;
3189 tempitemy=y;
3190 }
3191
3192 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3193 }
3194
3195 break;
3196
3197 case mfXSWORD:
3198 if(!hints)
3199 {
3200 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sXSWORD],scr->secretcset[sXSWORD]);
3201 }
3202 else
3203 {
3204 tempitem=getItemID(itemsbuf,itype_sword,4);
3205
3206 if(tempitem<0) break;
3207
3208 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3209 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3210 {
3211 tempitemx=x;
3212 tempitemy=y;
3213 }
3214
3215 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3216 }
3217
3218 break;
3219
3220 case mfSWORDBEAM:
3221
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(!hints)
3222 {
3223 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sSWORDBEAM],scr->secretcset[sSWORDBEAM]);
3224 }
3225 else
3226 {
3227 16 tempitem=getItemID(itemsbuf,itype_sword,1);
3228
3229
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(tempitem<0) break;
3230
3231
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
16 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3232
3/6
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 5 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
16 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3233 {
3234 11 tempitemx=x;
3235 11 tempitemy=y;
3236 11 }
3237
3238 16 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 1);
3239 }
3240
3241 16 break;
3242
3243 case mfWSWORDBEAM:
3244 if(!hints)
3245 {
3246 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sWSWORDBEAM],scr->secretcset[sWSWORDBEAM]);
3247 }
3248 else
3249 {
3250 tempitem=getItemID(itemsbuf,itype_sword,2);
3251
3252 if(tempitem<0) break;
3253
3254 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3255 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3256 {
3257 tempitemx=x;
3258 tempitemy=y;
3259 }
3260
3261 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 2);
3262 }
3263
3264 break;
3265
3266 case mfMSWORDBEAM:
3267 if(!hints)
3268 {
3269 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sMSWORDBEAM],scr->secretcset[sMSWORDBEAM]);
3270 }
3271 else
3272 {
3273 tempitem=getItemID(itemsbuf,itype_sword,3);
3274
3275 if(tempitem<0) break;
3276
3277 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3278 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3279 {
3280 tempitemx=x;
3281 tempitemy=y;
3282 }
3283
3284 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 3);
3285 }
3286
3287 break;
3288
3289 case mfXSWORDBEAM:
3290 if(!hints)
3291 {
3292 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sXSWORDBEAM],scr->secretcset[sXSWORDBEAM]);
3293 }
3294 else
3295 {
3296 tempitem=getItemID(itemsbuf,itype_sword,4);
3297
3298 if(tempitem<0) break;
3299
3300 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3301 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3302 {
3303 tempitemx=x;
3304 tempitemy=y;
3305 }
3306
3307 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 4);
3308 }
3309
3310 break;
3311
3312 case mfHOOKSHOT:
3313
1/2
✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
17 if(!hints)
3314 {
3315 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sHOOKSHOT],scr->secretcset[sHOOKSHOT]);
3316 }
3317 else
3318 {
3319 17 tempitem=getItemID(itemsbuf,itype_hookshot,1);
3320
3321
1/2
✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
17 if(tempitem<0) break;
3322
3323
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 17 times.
17 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3324
3/6
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 5 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
17 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3325 {
3326 12 tempitemx=x;
3327 12 tempitemy=y;
3328 12 }
3329
3330 17 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3331 }
3332
3333 17 break;
3334
3335 case mfWAND:
3336
1/2
✓ Branch 0 taken 35 times.
✗ Branch 1 not taken.
35 if(!hints)
3337 {
3338 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sWAND],scr->secretcset[sWAND]);
3339 }
3340 else
3341 {
3342 35 tempitem=getItemID(itemsbuf,itype_wand,1);
3343
3344
1/2
✓ Branch 0 taken 35 times.
✗ Branch 1 not taken.
35 if(tempitem<0) break;
3345
3346
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 35 times.
35 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3347
3/6
✓ Branch 0 taken 28 times.
✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 7 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
35 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3348 {
3349 28 tempitemx=x;
3350 28 tempitemy=y;
3351 28 }
3352
3353 35 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3354 }
3355
3356 35 break;
3357
3358 case mfHAMMER:
3359
1/2
✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
17 if(!hints)
3360 {
3361 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sHAMMER],scr->secretcset[sHAMMER]);
3362 }
3363 else
3364 {
3365 17 tempitem=getItemID(itemsbuf,itype_hammer,1);
3366
3367
1/2
✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
17 if(tempitem<0) break;
3368
3369
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 17 times.
17 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3370
3/6
✓ Branch 0 taken 13 times.
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 4 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
17 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3371 {
3372 13 tempitemx=x;
3373 13 tempitemy=y;
3374 13 }
3375
3376 17 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3377 }
3378
3379 17 break;
3380
3381 case mfARMOS_ITEM:
3382 case mfDIVE_ITEM:
3383
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 2602 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2602 times.
2602 if((!getmapflag(scr, mSPECIALITEM) || (scr->flags9&fBELOWRETURN)) && !(itemsbuf[Hero.getLastLensID()].flags & item_flag3))
3384 {
3385 7806 putitem2(dest,x,y,scr->catchall, lens_hint_item[scr->catchall][0], lens_hint_item[scr->catchall][1], 0);
3386 2602 }
3387 2602 break;
3388
3389 case 16:
3390 case 17:
3391 case 18:
3392 case 19:
3393 case 20:
3394 case 21:
3395 case 22:
3396 case 23:
3397 case 24:
3398 case 25:
3399 case 26:
3400 case 27:
3401 case 28:
3402 case 29:
3403 case 30:
3404 case 31:
3405
2/2
✓ Branch 0 taken 1008 times.
✓ Branch 1 taken 107890 times.
108898 if(!hints)
3406
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 107890 times.
215780 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))
3407 323670 putcombo(dest,x,y,scr->secretcombo[checkflag-16+4],scr->secretcset[checkflag-16+4]);
3408
3409 108898 break;
3410 case mfSECRETSNEXT:
3411 if(!hints)
3412 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))
3413 putcombo(dest,x,y,rpos_handle.data()+1,rpos_handle.cset());
3414
3415 break;
3416
3417 case mfSTRIKE:
3418
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 906 times.
906 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))
3419 {
3420 906 goto special;
3421 }
3422 else
3423 {
3424 break;
3425 }
3426
3427 28750 default: goto special;
3428
3429 special:
3430
8/8
✓ Branch 0 taken 14732 times.
✓ Branch 1 taken 14924 times.
✓ Branch 2 taken 528 times.
✓ Branch 3 taken 14204 times.
✓ Branch 4 taken 496 times.
✓ Branch 5 taken 32 times.
✓ Branch 6 taken 6108 times.
✓ Branch 7 taken 8128 times.
29656 if(layer && ((checkflag!=mfRAFT && checkflag!=mfRAFT_BRANCH&& checkflag!=mfRAFT_BOUNCE) ||(itemsbuf[Hero.getLastLensID()].flags & item_flag4)))
3431 {
3432
4/8
✗ Branch 0 not taken.
✓ Branch 1 taken 6604 times.
✓ Branch 2 taken 4954 times.
✓ Branch 3 taken 1650 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1650 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
6604 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate)) || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3433 {
3434 24770 rectfill(dest,x,y,x+15,y+15,WHITE);
3435 4954 }
3436 6604 }
3437
3438 29656 break;
3439 }
3440 7060416 }
3441 3530208 });
3442
3443 40116 for_every_base_screen_in_region([&](mapscr* scr, unsigned int region_scr_x, unsigned int region_scr_y) {
3444 90824 auto [offx, offy] = translate_screen_coordinates_to_world(scr->screen);
3445
3446 40116 offx -= viewport.x;
3447 40116 offy -= viewport.y;
3448 40116 offy += playing_field_offset;
3449
3450
2/2
✓ Branch 0 taken 10029 times.
✓ Branch 1 taken 10029 times.
20058 if (layer)
3451 {
3452
2/2
✓ Branch 0 taken 9670 times.
✓ Branch 1 taken 359 times.
10029 if (scr->door[0]==dWALK)
3453 1795 rectfill(dest, 120+offx, 16+offy, 135+offx, 31+offy, WHITE);
3454
3455
2/2
✓ Branch 0 taken 9606 times.
✓ Branch 1 taken 423 times.
10029 if (scr->door[1]==dWALK)
3456 2115 rectfill(dest, 120+offx, 144+offy, 135+offx, 159+offy, WHITE);
3457
3458
2/2
✓ Branch 0 taken 9447 times.
✓ Branch 1 taken 582 times.
10029 if (scr->door[2]==dWALK)
3459 2910 rectfill(dest, 16+offx, 80+offy, 31+offx, 95+offy, WHITE);
3460
3461
2/2
✓ Branch 0 taken 9405 times.
✓ Branch 1 taken 624 times.
10029 if (scr->door[3]==dWALK)
3462 3120 rectfill(dest, 224+offx, 80+offy, 239+offx, 95+offy, WHITE);
3463
3464
2/2
✓ Branch 0 taken 9986 times.
✓ Branch 1 taken 43 times.
10029 if (scr->door[0]==dBOMB)
3465 {
3466 129 showbombeddoor(scr, dest, 0, offx, offy);
3467 43 }
3468
3469
2/2
✓ Branch 0 taken 9990 times.
✓ Branch 1 taken 39 times.
10029 if (scr->door[1]==dBOMB)
3470 {
3471 117 showbombeddoor(scr, dest, 1, offx, offy);
3472 39 }
3473
3474
2/2
✓ Branch 0 taken 10023 times.
✓ Branch 1 taken 6 times.
10029 if (scr->door[2]==dBOMB)
3475 {
3476 18 showbombeddoor(scr, dest, 2, offx, offy);
3477 6 }
3478
3479
2/2
✓ Branch 0 taken 9992 times.
✓ Branch 1 taken 37 times.
10029 if (scr->door[3]==dBOMB)
3480 {
3481 111 showbombeddoor(scr, dest, 3, offx, offy);
3482 37 }
3483 10029 }
3484
3485
3/4
✓ Branch 0 taken 18024 times.
✓ Branch 1 taken 2034 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 18024 times.
20058 if (scr->stairx || scr->stairy)
3486 {
3487
2/2
✓ Branch 0 taken 911 times.
✓ Branch 1 taken 1123 times.
2034 if (!hints)
3488 {
3489
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1123 times.
1123 if (!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))
3490 3369 putcombo(dest,scr->stairx+offx,scr->stairy+offy,scr->secretcombo[sSTAIRS],scr->secretcset[sSTAIRS]);
3491 1123 }
3492 else
3493 {
3494
2/2
✓ Branch 0 taken 863 times.
✓ Branch 1 taken 48 times.
911 if(scr->flags&fWHISTLE)
3495 {
3496 48 tempitem=getItemID(itemsbuf,itype_whistle,1);
3497 48 int32_t tempitemx=-16+offx;
3498 48 int32_t tempitemy=-16+offy-playing_field_offset;
3499
3500
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 48 times.
48 if ((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&(blink_rate/4)))
3501
3/6
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 24 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
48 || ((get_debug() && zc_getkey(KEY_N)) && (frame&(blink_rate/4))))
3502 {
3503 48 tempitemx=scr->stairx+offx;
3504 48 tempitemy=scr->stairy+offy;
3505 24 }
3506
3507 48 putitem2(dest, tempitemx, tempitemy, tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3508 48 }
3509 }
3510 2034 }
3511 20058 });
3512 }
3513 20058 }
3514
3515 9690 void draw_lens_over()
3516 {
3517 9690 int w = 288;
3518 9690 int h = 240;
3519
3520
4/6
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9672 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 18 times.
✓ Branch 4 taken 18 times.
✗ Branch 5 not taken.
9690 static BITMAP *lens_scr = create_bitmap_ex(8,2*w,2*h);
3521 static int32_t last_width = -1;
3522 9690 int32_t width = itemsbuf[current_item_id(itype_lens,true)].misc1;
3523
3524 // Only redraw the circle if the size has changed
3525
2/2
✓ Branch 0 taken 9670 times.
✓ Branch 1 taken 20 times.
9690 if (width != last_width)
3526 {
3527 20 clear_to_color(lens_scr, BLACK);
3528 20 circlefill(lens_scr, w, h, width, 0);
3529 20 circle(lens_scr, w, h, width+2, 0);
3530 20 circle(lens_scr, w, h, width+5, 0);
3531 20 last_width=width;
3532 20 }
3533
3534 9690 masked_blit(lens_scr, framebuf, w-(HeroX()+8)+viewport.x, h-(HeroY()+8)+viewport.y, 0, playing_field_offset, 256, viewport.h);
3535 9690 do_primitives(framebuf, SPLAYER_LENS_OVER);
3536 9690 }
3537
3538 36714381 static void update_bmp_size(BITMAP** bmp_ptr, int w, int h)
3539 {
3540 36714381 BITMAP* bmp = *bmp_ptr;
3541
3/4
✓ Branch 0 taken 36714381 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 36714375 times.
✓ Branch 3 taken 6 times.
36714381 if (bmp->w == w && bmp->h == h)
3542 36714375 return;
3543
3544 6 int depth = bitmap_color_depth(bmp);
3545 6 destroy_bitmap(bmp);
3546 6 *bmp_ptr = create_bitmap_ex(depth, w, h);
3547 36714381 }
3548
3549 31797 void draw_wavy(BITMAP *source, BITMAP *target, int32_t amplitude, bool interpol)
3550 {
3551
4/6
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 31792 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 5 times.
✓ Branch 4 taken 5 times.
✗ Branch 5 not taken.
31797 static BITMAP *wavebuf = create_bitmap_ex(8,288,240-original_playing_field_offset);
3552 31797 update_bmp_size(&wavebuf, 288, 240 - original_playing_field_offset);
3553
3554 31797 clear_to_color(wavebuf, BLACK);
3555 31797 blit(source,wavebuf,0,original_playing_field_offset,16,0,256,framebuf->h-original_playing_field_offset);
3556
3557 int32_t ofs;
3558
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 31797 times.
31797 amplitude = zc_min(2048,amplitude); // some arbitrary limit to prevent crashing
3559
4/6
✓ Branch 0 taken 31797 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 31797 times.
✓ Branch 4 taken 494 times.
✓ Branch 5 taken 31303 times.
31797 if(flash_reduction_enabled() && !get_qr(qr_WAVY_NO_EPILEPSY)) amplitude = zc_min(16,amplitude);
3560 31797 int32_t amp2 = viewport.visible_height(show_bottom_8px);
3561
2/4
✓ Branch 0 taken 31797 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 31797 times.
31797 if(flash_reduction_enabled() && !get_qr(qr_WAVY_NO_EPILEPSY_2)) amp2*=2;
3562 31797 int32_t i=frame%amp2;
3563
3564
2/2
✓ Branch 0 taken 5341896 times.
✓ Branch 1 taken 31797 times.
5373693 for(int32_t j=0; j<viewport.visible_height(show_bottom_8px); j++)
3565 {
3566
3/4
✓ Branch 0 taken 2670948 times.
✓ Branch 1 taken 2670948 times.
✓ Branch 2 taken 2670948 times.
✗ Branch 3 not taken.
5341896 if(j&1 && interpol)
3567 {
3568 // Add 288*2048 to ensure it's never negative. It'll get modded out.
3569 ofs=288*2048+int32_t(zc::math::Sin((double(i+j)*2*PI/amp2))*amplitude);
3570 }
3571 else
3572 {
3573 5341896 ofs=288*2048-int32_t(zc::math::Sin((double(i+j)*2*PI/amp2))*amplitude);
3574 }
3575
3576
1/2
✓ Branch 0 taken 5341896 times.
✗ Branch 1 not taken.
5341896 if(ofs)
3577 {
3578
2/2
✓ Branch 0 taken 1367525376 times.
✓ Branch 1 taken 5341896 times.
1372867272 for(int32_t k=0; k<256; k++)
3579 {
3580 1367525376 target->line[j+original_playing_field_offset][k]=wavebuf->line[j][(k+ofs+16)%288];
3581 1367525376 }
3582 5341896 }
3583 5341896 }
3584 31797 }
3585
3586 27792 void draw_fuzzy(int32_t fuzz)
3587 // draws from right half of scrollbuf to framebuf
3588 {
3589 int32_t firstx, firsty, xstep, ystep, i, y, dx, dy;
3590 byte *start, *si, *di;
3591
3592
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 27792 times.
27792 if(fuzz<1)
3593 fuzz = 1;
3594
3595 27792 xstep = 128%fuzz;
3596
3597
2/2
✓ Branch 0 taken 5790 times.
✓ Branch 1 taken 22002 times.
27792 if(xstep > 0)
3598 22002 xstep = fuzz-xstep;
3599
3600 27792 ystep = 112%fuzz;
3601
3602
2/2
✓ Branch 0 taken 8106 times.
✓ Branch 1 taken 19686 times.
27792 if(ystep > 0)
3603 19686 ystep = fuzz-ystep;
3604
3605 27792 firsty = 1;
3606
3607
2/2
✓ Branch 0 taken 27792 times.
✓ Branch 1 taken 1002828 times.
1030620 for(y=0; y<framebuf->h;)
3608 {
3609 1002828 start = &(scrollbuf_old->line[y][256]);
3610
3611
4/4
✓ Branch 0 taken 988932 times.
✓ Branch 1 taken 6239304 times.
✓ Branch 2 taken 6225408 times.
✓ Branch 3 taken 1002828 times.
7228236 for(dy=0; dy<ystep && dy+y<framebuf->h; dy++)
3612 {
3613 6225408 si = start;
3614 6225408 di = &(framebuf->line[y+dy][0]);
3615 6225408 i = xstep;
3616 6225408 firstx = 1;
3617
3618
2/2
✓ Branch 0 taken 1593704448 times.
✓ Branch 1 taken 6225408 times.
1599929856 for(dx=0; dx<framebuf->w; dx++)
3619 {
3620 1593704448 *(di++) = *si;
3621
3622
2/2
✓ Branch 0 taken 1342872384 times.
✓ Branch 1 taken 250832064 times.
1593704448 if(++i >= fuzz)
3623 {
3624
2/2
✓ Branch 0 taken 244606656 times.
✓ Branch 1 taken 6225408 times.
250832064 if(!firstx)
3625 244606656 si += fuzz;
3626 else
3627 {
3628 6225408 si += fuzz-xstep;
3629 6225408 firstx = 0;
3630 }
3631
3632 250832064 i = 0;
3633 250832064 }
3634 1593704448 }
3635 6225408 }
3636
3637
2/2
✓ Branch 0 taken 975036 times.
✓ Branch 1 taken 27792 times.
1002828 if(!firsty)
3638 975036 y += fuzz;
3639 else
3640 {
3641 27792 y += ystep;
3642 27792 ystep = fuzz;
3643 27792 firsty = 0;
3644 }
3645 }
3646 27792 }
3647
3648 18341292 void updatescr(bool allowwavy)
3649 {
3650
4/6
✓ Branch 0 taken 308 times.
✓ Branch 1 taken 18340984 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 308 times.
✓ Branch 4 taken 308 times.
✗ Branch 5 not taken.
18341292 static BITMAP *wavybuf = create_bitmap_ex(8, framebuf->w, framebuf->h);
3651
4/6
✓ Branch 0 taken 308 times.
✓ Branch 1 taken 18340984 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 308 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 308 times.
18341292 static BITMAP *panorama = create_bitmap_ex(8, framebuf->w, framebuf->h);
3652 18341292 update_bmp_size(&wavybuf, framebuf->w, framebuf->h);
3653 18341292 update_bmp_size(&panorama, framebuf->w, framebuf->h);
3654
3655
2/2
✓ Branch 0 taken 18313191 times.
✓ Branch 1 taken 28101 times.
18341292 if(toogam)
3656 {
3657 28101 textout_ex(framebuf,font,"no walls",8,216,1,-1);
3658 28101 }
3659
3660
1/2
✓ Branch 0 taken 18341292 times.
✗ Branch 1 not taken.
18341292 if(Showpal)
3661 dump_pal(framebuf);
3662
3663
2/2
✓ Branch 0 taken 17830019 times.
✓ Branch 1 taken 511273 times.
18341292 if(!Playing)
3664 511273 black_opening_count=0;
3665
3666
2/2
✓ Branch 0 taken 18175806 times.
✓ Branch 1 taken 165486 times.
18341292 if(black_opening_count<0) //shape is opening up
3667 {
3668 165486 black_opening(framebuf,black_opening_x,black_opening_y,(66+black_opening_count),66);
3669
3670
2/4
✓ Branch 0 taken 165486 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 165486 times.
165486 if(Advance||(!Paused))
3671 {
3672 165486 ++black_opening_count;
3673 165486 }
3674 165486 }
3675
2/2
✓ Branch 0 taken 18127098 times.
✓ Branch 1 taken 48708 times.
18175806 else if(black_opening_count>0) //shape is closing
3676 {
3677 48708 black_opening(framebuf,black_opening_x,black_opening_y,black_opening_count,66);
3678
3679
2/4
✓ Branch 0 taken 48708 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 48708 times.
48708 if(Advance||(!Paused))
3680 {
3681 48708 --black_opening_count;
3682 48708 }
3683 48708 }
3684
3685
3/4
✓ Branch 0 taken 18130343 times.
✓ Branch 1 taken 210949 times.
✓ Branch 2 taken 18130343 times.
✗ Branch 3 not taken.
18341292 if(black_opening_count==0&&black_opening_shape==bosFADEBLACK)
3686 {
3687 black_opening_shape = bosCIRCLE;
3688 memcpy(RAMpal, tempblackpal, PAL_SIZE*sizeof(RGB));
3689 refreshTints();
3690 refreshpal=true;
3691 }
3692
3693
2/2
✓ Branch 0 taken 17709428 times.
✓ Branch 1 taken 631864 times.
18341292 if(refreshpal)
3694 {
3695 631864 refreshpal=false;
3696 631864 RAMpal[253] = _RGB(0,0,0);
3697 631864 RAMpal[254] = _RGB(255,255,255);
3698 631864 hw_palette = &RAMpal;
3699 631864 update_hw_pal = true;
3700 631864 refresh_rgb_tables();
3701 631864 }
3702
3703 18341292 bool clearwavy = (wavy <= 0);
3704
3705
2/2
✓ Branch 0 taken 8341 times.
✓ Branch 1 taken 18332951 times.
18341292 if(wavy <= 0)
3706 {
3707 // So far one thing can alter wavy apart from scripts: Wavy DMaps.
3708 18332951 wavy = (DMaps[cur_dmap].flags&dmfWAVY ? 4 : 0);
3709 18332951 }
3710
3711 18341292 blit(framebuf, wavybuf, 0, 0, 0, 0, framebuf->w, framebuf->h);
3712
3713
6/6
✓ Branch 0 taken 32047 times.
✓ Branch 1 taken 18309245 times.
✓ Branch 2 taken 31925 times.
✓ Branch 3 taken 122 times.
✓ Branch 4 taken 128 times.
✓ Branch 5 taken 31797 times.
18341292 if(wavy && Playing && allowwavy)
3714 {
3715 31797 draw_wavy(framebuf, wavybuf, wavy,false);
3716 31797 }
3717
3718
2/2
✓ Branch 0 taken 18332951 times.
✓ Branch 1 taken 8341 times.
18341292 if(clearwavy)
3719 18332951 wavy = 0; // Wavy was set by a DMap flag. Clear it.
3720
2/4
✓ Branch 0 taken 8341 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 8341 times.
8341 else if(Playing && !Paused)
3721 8341 wavy--; // Wavy was set by a script. Decrement it.
3722
3723
3/4
✓ Branch 0 taken 17830019 times.
✓ Branch 1 taken 511273 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 17830019 times.
18341292 if(Playing && !Paused)
3724 17830019 ++light_wave_clk;
3725
3726
6/6
✓ Branch 0 taken 17830019 times.
✓ Branch 1 taken 511273 times.
✓ Branch 2 taken 257497 times.
✓ Branch 3 taken 17572522 times.
✓ Branch 4 taken 18 times.
✓ Branch 5 taken 257479 times.
18341292 if(Playing && msg_active && !screenscrolling)
3727 {
3728
2/2
✓ Branch 0 taken 67 times.
✓ Branch 1 taken 257412 times.
257479 if(!(msg_bg_display_buf->clip))
3729 257412 blit_msgstr_bg(framebuf,0,0,0,playing_field_offset,256,176);
3730
2/2
✓ Branch 0 taken 67 times.
✓ Branch 1 taken 257412 times.
257479 if(!(msg_portrait_display_buf->clip))
3731 257412 blit_msgstr_prt(framebuf,0,0,0,playing_field_offset,256,176);
3732
2/2
✓ Branch 0 taken 67 times.
✓ Branch 1 taken 257412 times.
257479 if(!(msg_txt_display_buf->clip))
3733 257412 blit_msgstr_fg(framebuf,0,0,0,playing_field_offset,256,176);
3734 257479 }
3735
3736
3/4
✓ Branch 0 taken 18341292 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 18147565 times.
✓ Branch 3 taken 193727 times.
18341292 bool nosubscr = GameLoaded && no_subscreen() && !(hero_scr->flags3&fNOSUBSCROFFSET);
3737
3738
2/2
✓ Branch 0 taken 18152838 times.
✓ Branch 1 taken 188454 times.
18341292 if(nosubscr)
3739 {
3740 188454 clear_to_color(panorama, 0);
3741 188454 blit(wavybuf,panorama,0,playing_field_offset,0,playing_field_offset/2,256,framebuf->h-playing_field_offset);
3742 188454 }
3743
3744 //TODO: Optimize blit 'overcalls' -Gleeok
3745
2/2
✓ Branch 0 taken 188454 times.
✓ Branch 1 taken 18152838 times.
18341292 BITMAP *source = nosubscr ? panorama : wavybuf;
3746 18341292 blit(source, framebuf, 0, 0, 0, 0, framebuf->w, framebuf->h);
3747
3748 18341292 update_hw_screen();
3749 18341292 }
3750
3751 //----------------------------------------------------------------
3752
3753 static PALETTE syspal;
3754 int32_t onGUISnapshot()
3755 {
3756 char buf[200];
3757 int32_t num=0;
3758 do
3759 {
3760 sprintf(buf, "%szc_screen%05d.%s", get_snap_str(), ++num, snapshotformat_str[SnapshotFormat][1]);
3761 }
3762 while(num<99999 && exists(buf));
3763
3764 if (!al_save_bitmap(buf, al_get_backbuffer(all_get_display())))
3765 InfoDialog("Error", "Failed to save snapshot").show();
3766
3767 return D_O_K;
3768 }
3769
3770 int32_t onNonGUISnapshot()
3771 {
3772 PALETTE temppal;
3773 get_palette(temppal);
3774 bool realpal=(zc_getkey(KEY_ZC_LCONTROL, true) || zc_getkey(KEY_ZC_RCONTROL, true));
3775
3776 char buf[200];
3777 int32_t num=0;
3778
3779 do
3780 {
3781 sprintf(buf, "%szc_screen%05d.%s", get_snap_str(), ++num, snapshotformat_str[SnapshotFormat][1]);
3782 }
3783 while(num<99999 && exists(buf));
3784
3785 if (no_subscreen() && !(hero_scr->flags3&fNOSUBSCROFFSET) && !key[KEY_ALT])
3786 {
3787 BITMAP *b = create_bitmap_ex(8, 256, viewport.visible_height(show_bottom_8px));
3788 clear_to_color(b,0);
3789 blit(framebuf,b,0,playing_field_offset/2,0,0,b->w,b->h);
3790 alleg4_save_bitmap(b, SnapshotScale, buf, realpal ? temppal : RAMpal);
3791 destroy_bitmap(b);
3792 }
3793 else
3794 {
3795 alleg4_save_bitmap(framebuf, SnapshotScale, buf, realpal?temppal:RAMpal);
3796 }
3797
3798 return D_O_K;
3799 }
3800
3801 int32_t onSnapshot()
3802 {
3803 if(zc_getkey(KEY_LSHIFT, true)||zc_getkey(KEY_RSHIFT, true))
3804 {
3805 onGUISnapshot();
3806 }
3807 else
3808 {
3809 onNonGUISnapshot();
3810 }
3811
3812 return D_O_K;
3813 }
3814
3815 int32_t onSaveMapPic()
3816 {
3817 char buf[200];
3818 int32_t num=0;
3819 BITMAP* _screen_draw_buffer = NULL;
3820 _screen_draw_buffer = create_bitmap_ex(8,256,176);
3821
3822 do
3823 {
3824 sprintf(buf, "%szc_screen%05d.png", get_snap_str(), ++num);
3825 }
3826 while(num<99999 && exists(buf));
3827
3828 BITMAP* mappic = create_bitmap_ex(8,(256*16),(176*8));
3829 clear_to_color(mappic, BLACK);
3830
3831 if(!mappic)
3832 {
3833 enter_sys_pal();
3834 jwin_alert("View Map","Not enough memory.",NULL,NULL,"OK",NULL,13,27,get_zc_font(font_lfont));
3835 exit_sys_pal();
3836 return D_O_K;;
3837 }
3838
3839 clear_to_color(_screen_draw_buffer, BLACK);
3840
3841 auto prev_viewport = viewport;
3842 viewport.x = 0;
3843 viewport.y = 0;
3844
3845 // draw the map
3846
3847 for(int32_t y=0; y<8; y++)
3848 {
3849 for(int32_t x=0; x<16; x++)
3850 {
3851 if (!displayOnMap(x, y))
3852 continue;
3853
3854 int screen = map_scr_xy_to_index(x, y);
3855 auto scrs = loadscr2(screen);
3856 mapscr* scr = &scrs[0];
3857 if (!scr->is_valid())
3858 continue;
3859
3860 screen_handles_t screen_handles;
3861 for (int i = 0; i <= 6; i++)
3862 screen_handles[i] = {scr, scrs[i].is_valid() ? &scrs[i] : nullptr, screen, i};
3863
3864 int xx = 0;
3865 int yy = -playing_field_offset;
3866
3867 if(XOR(scr->flags7&fLAYER2BG, DMaps[cur_dmap].flags&dmfLAYER2BG))
3868 {
3869 do_layer(_screen_draw_buffer, 0, screen_handles[2], xx, yy);
3870 do_ffc_layer(_screen_draw_buffer, -2, screen_handles[0], xx, yy);
3871 }
3872
3873 if(XOR(scr->flags7&fLAYER3BG, DMaps[cur_dmap].flags&dmfLAYER3BG))
3874 {
3875 do_layer(_screen_draw_buffer, 0, screen_handles[3], xx, yy);
3876 do_ffc_layer(_screen_draw_buffer, -3, screen_handles[0], xx, yy);
3877 }
3878
3879 if(lenscheck(scr,0))
3880 putscr(scr, _screen_draw_buffer, 0, 0);
3881 do_ffc_layer(_screen_draw_buffer, 0, screen_handles[0], xx, yy);
3882 do_layer(_screen_draw_buffer, 0, screen_handles[1], xx, yy);
3883 do_ffc_layer(_screen_draw_buffer, 1, screen_handles[0], xx, yy);
3884
3885 if(!XOR(scr->flags7&fLAYER2BG, DMaps[cur_dmap].flags&dmfLAYER2BG))
3886 {
3887 do_layer(_screen_draw_buffer, 0, screen_handles[2], xx, yy);
3888 do_ffc_layer(_screen_draw_buffer, 2, screen_handles[0], xx, yy);
3889 }
3890
3891 putscrdoors(scr, _screen_draw_buffer, xx, yy);
3892 if(get_qr(qr_PUSHBLOCK_SPRITE_LAYER))
3893 {
3894 do_layer(_screen_draw_buffer, -2, screen_handles[0], xx, yy);
3895 if(get_qr(qr_PUSHBLOCK_LAYER_1_2))
3896 {
3897 do_layer(_screen_draw_buffer, -2, screen_handles[1], xx, yy);
3898 do_layer(_screen_draw_buffer, -2, screen_handles[2], xx, yy);
3899 }
3900 }
3901
3902 if(!XOR(scr->flags7&fLAYER3BG, DMaps[cur_dmap].flags&dmfLAYER3BG))
3903 {
3904 do_layer(_screen_draw_buffer, 0, screen_handles[3], xx, yy);
3905 do_ffc_layer(_screen_draw_buffer, 3, screen_handles[0], xx, yy);
3906 }
3907
3908 do_layer(_screen_draw_buffer, 0, screen_handles[4], xx, yy);
3909 do_ffc_layer(_screen_draw_buffer, 4, screen_handles[0], xx, yy);
3910 do_layer(_screen_draw_buffer, -1, screen_handles[0], xx, yy);
3911 if(get_qr(qr_OVERHEAD_COMBOS_L1_L2))
3912 {
3913 do_layer(_screen_draw_buffer, -1, screen_handles[1], xx, yy);
3914 do_layer(_screen_draw_buffer, -1, screen_handles[2], xx, yy);
3915 }
3916 do_layer(_screen_draw_buffer, 0, screen_handles[5], xx, yy);
3917 do_ffc_layer(_screen_draw_buffer, 5, screen_handles[0], xx, yy);
3918 if(replay_version_check(40))
3919 do_ffc_layer(_screen_draw_buffer, -1, screen_handles[0], xx, yy);
3920 do_layer(_screen_draw_buffer, 0, screen_handles[6], xx, yy);
3921 do_ffc_layer(_screen_draw_buffer, 6, screen_handles[0], xx, yy);
3922 do_ffc_layer(_screen_draw_buffer, 7, screen_handles[0], xx, yy);
3923
3924 blit(_screen_draw_buffer, mappic, 0, 0, x*256, y*176, 256, 176);
3925 }
3926 }
3927
3928 viewport = prev_viewport;
3929 save_bitmap(buf,mappic,RAMpal);
3930 destroy_bitmap(mappic);
3931 destroy_bitmap(_screen_draw_buffer);
3932 return D_O_K;
3933 }
3934
3935 45 void f_Quit(int32_t type)
3936 {
3937
2/4
✓ Branch 0 taken 45 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 45 times.
✗ Branch 3 not taken.
45 if(type==qQUIT && !Playing)
3938 return;
3939
3940 45 bool from_menu = is_sys_pal;
3941
3942
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 45 times.
45 if(!from_menu)
3943 {
3944 45 music_pause();
3945 45 pause_all_sfx();
3946 45 sys_mouse();
3947 45 }
3948 45 enter_sys_pal();
3949 45 clear_keybuf();
3950
3951
2/2
✓ Branch 0 taken 32 times.
✓ Branch 1 taken 13 times.
45 if (replay_version_check(0, 10))
3952 13 replay_poll();
3953
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 45 times.
45 if (replay_is_replaying())
3954 45 replay_peek_quit();
3955
3956
1/2
✓ Branch 0 taken 45 times.
✗ Branch 1 not taken.
45 if (!replay_is_replaying())
3957 switch(type)
3958 {
3959 case qQUIT:
3960 onQuit();
3961 break;
3962
3963 case qRESET:
3964 onReset();
3965 break;
3966
3967 case qEXIT:
3968 onExit();
3969 break;
3970 }
3971
3972
1/2
✓ Branch 0 taken 45 times.
✗ Branch 1 not taken.
45 if(Quit)
3973 {
3974 45 kill_sfx();
3975 45 music_stop();
3976 45 exit_sys_pal();
3977 45 update_hw_screen();
3978 45 }
3979 else
3980 {
3981 exit_sys_pal();
3982 if(!from_menu)
3983 {
3984 music_resume();
3985 resume_all_sfx();
3986 }
3987 }
3988
3989
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 45 times.
45 if(!from_menu)
3990 45 game_mouse();
3991 45 eat_buttons();
3992
3993 45 zc_readrawkey(KEY_ESC);
3994
3995 45 zc_readrawkey(KEY_ENTER);
3996 45 }
3997
3998 //----------------------------------------------------------------
3999
4000 int32_t onNoWalls()
4001 {
4002 cheats_enqueue(Cheat::Walls);
4003 return D_O_K;
4004 }
4005
4006 int32_t onIgnoreSideview()
4007 {
4008 cheats_enqueue(Cheat::IgnoreSideView);
4009 return D_O_K;
4010 }
4011
4012 18339918 int32_t input_idle(bool checkmouse)
4013 {
4014 static int32_t mx, my, mz, mb;
4015
4016
4/6
✓ Branch 0 taken 18339918 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4916157 times.
✓ Branch 3 taken 13423761 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 4916157 times.
23256075 if(keypressed() || zc_key_pressed() ||
4017
4/8
✓ Branch 0 taken 4916157 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4916157 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4916157 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 4916157 times.
✗ Branch 7 not taken.
4916157 (checkmouse && (mx != mouse_x || my != mouse_y || mz != mouse_z || mb != mouse_b)))
4018 {
4019 13423761 idle_count = 0;
4020
4021
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 13423761 times.
13423761 if(active_count < MAX_ACTIVE)
4022 {
4023 13423761 ++active_count;
4024 13423761 }
4025 13423761 }
4026
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4916157 times.
4916157 else if(idle_count < MAX_IDLE)
4027 {
4028 4916157 ++idle_count;
4029 4916157 active_count = 0;
4030 4916157 }
4031
4032 18339918 mx = mouse_x;
4033 18339918 my = mouse_y;
4034 18339918 mz = mouse_z;
4035 18339918 mb = mouse_b;
4036
4037 18339918 return idle_count;
4038 }
4039
4040 int32_t onGoFast()
4041 {
4042 cheats_enqueue(Cheat::Fast);
4043 return D_O_K;
4044 }
4045
4046 int32_t onKillCheat()
4047 {
4048 cheats_enqueue(Cheat::Kill);
4049 return D_O_K;
4050 }
4051
4052 int32_t onSecretsCheat()
4053 {
4054 cheats_enqueue(Cheat::TrigSecrets);
4055 return D_O_K;
4056 }
4057 int32_t onSecretsCheatPerm()
4058 {
4059 cheats_enqueue(Cheat::TrigSecretsPerm);
4060 return D_O_K;
4061 }
4062
4063 int32_t onShowLayer0()
4064 {
4065 show_layers[0] = !show_layers[0];
4066 return D_O_K;
4067 }
4068 int32_t onShowLayer1()
4069 {
4070 show_layers[1] = !show_layers[1];
4071 return D_O_K;
4072 }
4073 int32_t onShowLayer2()
4074 {
4075 show_layers[2] = !show_layers[2];
4076 return D_O_K;
4077 }
4078 int32_t onShowLayer3()
4079 {
4080 show_layers[3] = !show_layers[3];
4081 return D_O_K;
4082 }
4083 int32_t onShowLayer4()
4084 {
4085 show_layers[4] = !show_layers[4];
4086 return D_O_K;
4087 }
4088 int32_t onShowLayer5()
4089 {
4090 show_layers[5] = !show_layers[5];
4091 return D_O_K;
4092 }
4093 int32_t onShowLayer6()
4094 {
4095 show_layers[6] = !show_layers[6];
4096 return D_O_K;
4097 }
4098 int32_t onShowLayerO()
4099 {
4100 show_layer_over=!show_layer_over;
4101 return D_O_K;
4102 }
4103 int32_t onShowLayerP()
4104 {
4105 show_layer_push=!show_layer_push;
4106 return D_O_K;
4107 }
4108 int32_t onShowLayerS()
4109 {
4110 show_sprites=!show_sprites;
4111 return D_O_K;
4112 }
4113 int32_t onShowLayerF()
4114 {
4115 show_ffcs=!show_ffcs;
4116 return D_O_K;
4117 }
4118 int32_t onShowLayerW()
4119 {
4120 show_walkflags=!show_walkflags;
4121 if(show_walkflags)
4122 show_effectflags = false;
4123 return D_O_K;
4124 }
4125 int32_t onShowLayerE()
4126 {
4127 show_effectflags=!show_effectflags;
4128 if(show_effectflags)
4129 show_walkflags = false;
4130 return D_O_K;
4131 }
4132 int32_t onShowFFScripts()
4133 {
4134 show_ff_scripts=!show_ff_scripts;
4135 return D_O_K;
4136 }
4137 int32_t onShowHitboxes()
4138 {
4139 show_hitboxes=!show_hitboxes;
4140 return D_O_K;
4141 }
4142 int32_t onShowInfoOpacity()
4143 {
4144 info_opacity = vbound(getnumber("Debug Info Opacity",info_opacity),0,255);
4145 zc_set_config("zc","debug_info_opacity",info_opacity);
4146 return D_O_K;
4147 }
4148
4149 int32_t onLightSwitch()
4150 {
4151 cheats_enqueue(Cheat::Light);
4152 return D_O_K;
4153 }
4154
4155 int32_t onGoTo();
4156 int32_t onGoToComplete();
4157
4158 18339918 bool handle_close_btn_quit()
4159 {
4160
1/2
✓ Branch 0 taken 18339918 times.
✗ Branch 1 not taken.
18339918 if(close_button_quit)
4161 {
4162 close_button_quit=false;
4163 f_Quit(qEXIT);
4164 }
4165 18339918 return (exiting_program = Quit==qEXIT);
4166 }
4167
4168 18339918 void syskeys()
4169 {
4170 18339918 update_system_keys();
4171
4172 int32_t oldtitle_version;
4173
4174 18339918 poll_joystick();
4175
4176 18339918 handle_close_btn_quit();
4177
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18339918 times.
18339918 if(Quit == qEXIT) return;
4178
4179
2/10
✓ Branch 0 taken 18339918 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 18339918 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
18339918 if(rMbtn() || (gui_mouse_b() && !mouse_down && ClickToFreeze &&!disableClickToFreeze))
4180 {
4181 System();
4182 }
4183
4184 18339918 mouse_down=gui_mouse_b();
4185
4186
1/2
✓ Branch 0 taken 18339918 times.
✗ Branch 1 not taken.
18339918 if(zc_read_system_key(KEY_F1))
4187 {
4188 if(zc_get_system_key(KEY_ZC_LCONTROL) || zc_get_system_key(KEY_ZC_RCONTROL))
4189 {
4190 halt=!halt;
4191 //zinit.subscreen=(zinit.subscreen+1)%ssdtMAX;
4192 }
4193 else
4194 {
4195 Throttlefps=!Throttlefps;
4196 zc_set_config(cfg_sect,"throttlefps", (int32_t)Throttlefps);
4197 }
4198 }
4199
4200
1/2
✓ Branch 0 taken 18339918 times.
✗ Branch 1 not taken.
18339918 if(zc_read_system_key(KEY_F2))
4201 {
4202 ShowFPS=!ShowFPS;
4203 zc_set_config(cfg_sect,"showfps",(int32_t)ShowFPS);
4204 }
4205
4206
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 18339918 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
18339918 if(zc_read_system_key(KEY_F3) && Playing) Paused=!Paused;
4207
4208
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 18339918 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
18339918 if(zc_read_system_key(KEY_F4) && Playing)
4209 {
4210 Paused=true;
4211 Advance=true;
4212 }
4213
4214
1/2
✓ Branch 0 taken 18339918 times.
✗ Branch 1 not taken.
18339918 if(zc_read_system_key(KEY_F6)) onTryQuit();
4215
4216 #ifndef ALLEGRO_MACOSX
4217
1/2
✓ Branch 0 taken 18339918 times.
✗ Branch 1 not taken.
18339918 if(zc_read_system_key(KEY_F9)) f_Quit(qRESET);
4218
4219
1/2
✓ Branch 0 taken 18339918 times.
✗ Branch 1 not taken.
18339918 if(zc_read_system_key(KEY_F10)) f_Quit(qEXIT);
4220 #else
4221 if(zc_read_system_key(KEY_F7)) f_Quit(qRESET);
4222
4223 if(zc_read_system_key(KEY_F8)) f_Quit(qEXIT);
4224 #endif
4225
1/8
✗ Branch 0 not taken.
✓ Branch 1 taken 18339918 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
18339918 if(zc_read_system_key(KEY_F5)&&(Playing && cur_screen<128 && DMaps[cur_dmap].flags&dmfVIEWMAP)) onSaveMapPic();
4226
4227
1/2
✓ Branch 0 taken 18339918 times.
✗ Branch 1 not taken.
18339918 if (zc_read_system_key(KEY_F12))
4228 {
4229 onSnapshot();
4230 }
4231
4232
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 18339918 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
18339918 if(debug_enabled && zc_read_system_key(KEY_TAB))
4233 set_debug(!get_debug());
4234
4235
1/2
✓ Branch 0 taken 18339918 times.
✗ Branch 1 not taken.
18339918 if(CheatModifierKeys())
4236 {
4237 for(Cheat c = (Cheat)1; c < Cheat::Last; c = (Cheat)(c+1))
4238 {
4239 if(!bindable_cheat(c))
4240 continue;
4241 if(get_debug() || cheat >= cheat_lvl(c))
4242 {
4243 if(checkcheat(c))
4244 cheats_hit_bind(c);
4245 }
4246 }
4247 }
4248
4249
1/2
✓ Branch 0 taken 18339918 times.
✗ Branch 1 not taken.
18339918 if(volkeys)
4250 {
4251 if(zc_read_system_key(KEY_PGUP)) master_volume(-1,midi_volume+8);
4252
4253 if(zc_read_system_key(KEY_PGDN)) master_volume(-1,midi_volume==255?248:midi_volume-8);
4254
4255 if(zc_read_system_key(KEY_HOME)) master_volume(digi_volume+8,-1);
4256
4257 if(zc_read_system_key(KEY_END)) master_volume(digi_volume==255?248:digi_volume-8,-1);
4258 }
4259
4260
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 18339918 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
18339918 if(!get_debug() || !SystemKeys || replay_is_replaying())
4261 18339918 goto bottom;
4262
4263 if(zc_readkey(KEY_P)) Paused=!Paused;
4264
4265 if(zc_readkey(KEY_A))
4266 {
4267 Paused=true;
4268 Advance=true;
4269 }
4270
4271 if(zc_readkey(KEY_G)) db=(db==999)?0:999;
4272 #ifndef ALLEGRO_MACOSX
4273 if(zc_readkey(KEY_F8)) Showpal=!Showpal;
4274
4275 if(zc_readkey(KEY_F7))
4276 {
4277 Matrix(ss_speed, ss_density, 0);
4278 game_pal();
4279 }
4280 #else
4281 // The reason these are different on Mac in the first place is that
4282 // the OS doesn't let us use F9 and F10...
4283 if(zc_readkey(KEY_F10)) Showpal=!Showpal;
4284
4285 if(zc_readkey(KEY_F9))
4286 {
4287 Matrix(ss_speed, ss_density, 0);
4288 game_pal();
4289 }
4290 #endif
4291 if(zc_readkey(KEY_PLUS_PAD) || zc_readkey(KEY_EQUALS))
4292 {
4293 //change containers
4294 if(zc_getkey(KEY_ZC_LCONTROL) || zc_getkey(KEY_ZC_RCONTROL))
4295 {
4296 //magic containers
4297 if(zc_getkey(KEY_LSHIFT) || zc_getkey(KEY_RSHIFT))
4298 {
4299 game->set_maxmagic(zc_min(game->get_maxmagic()+game->get_mp_per_block(),game->get_mp_per_block()*8));
4300 }
4301 else
4302 {
4303 game->set_maxlife(zc_min(game->get_maxlife()+game->get_hp_per_heart(),game->get_hp_per_heart()*24));
4304 }
4305 }
4306 else
4307 {
4308 if(zc_getkey(KEY_LSHIFT) || zc_getkey(KEY_RSHIFT))
4309 {
4310 game->set_magic(zc_min(game->get_magic()+1,game->get_maxmagic()));
4311 }
4312 else
4313 {
4314 game->set_life(zc_min(game->get_life()+1,game->get_maxlife()));
4315 }
4316 }
4317 }
4318
4319 if(zc_readkey(KEY_MINUS_PAD) || zc_readkey(KEY_MINUS))
4320 {
4321 //change containers
4322 if(zc_getkey(KEY_ZC_LCONTROL) || zc_getkey(KEY_ZC_RCONTROL))
4323 {
4324 //magic containers
4325 if(zc_getkey(KEY_LSHIFT) || zc_getkey(KEY_RSHIFT))
4326 {
4327 game->set_maxmagic(zc_max(game->get_maxmagic()-game->get_mp_per_block(),0));
4328 game->set_magic(zc_min(game->get_maxmagic(), game->get_magic()));
4329 //heart containers
4330 }
4331 else
4332 {
4333 game->set_maxlife(zc_max(game->get_maxlife()-game->get_hp_per_heart(),game->get_hp_per_heart()));
4334 game->set_life(zc_min(game->get_maxlife(), game->get_life()));
4335 }
4336 }
4337 else
4338 {
4339 if(zc_getkey(KEY_LSHIFT) || zc_getkey(KEY_RSHIFT))
4340 {
4341 game->set_magic(zc_max(game->get_magic()-1,0));
4342 }
4343 else
4344 {
4345 game->set_life(zc_max(game->get_life()-1,0));
4346 }
4347 }
4348 }
4349
4350 if(zc_readkey(KEY_COMMA)) jukebox(currmidi-1);
4351
4352 if(zc_readkey(KEY_STOP)) jukebox(currmidi+1);
4353
4354 verifyBothWeapons();
4355
4356 bottom:
4357
4358
1/2
✓ Branch 0 taken 18339918 times.
✗ Branch 1 not taken.
18339918 if(input_idle(true) > after_time())
4359 {
4360 Matrix(ss_speed, ss_density, 0);
4361 game_pal();
4362 }
4363 18339918 }
4364
4365 1147709 void checkQuitKeys()
4366 {
4367 #ifndef ALLEGRO_MACOSX
4368
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1147709 times.
1147709 if(key[KEY_F9]) f_Quit(qRESET);
4369
4370
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1147709 times.
1147709 if(key[KEY_F10]) f_Quit(qEXIT);
4371 #else
4372 if(key[KEY_F7]) f_Quit(qRESET);
4373
4374 if(key[KEY_F8]) f_Quit(qEXIT);
4375 #endif
4376 1147709 }
4377
4378 18340118 bool CheatModifierKeys()
4379 {
4380 // Cheats are replayed via the X cheat step, no need to check for keyboard input
4381 // to trigger cheats.
4382
2/2
✓ Branch 0 taken 18339818 times.
✓ Branch 1 taken 300 times.
18340118 if (replay_is_replaying())
4383 18339818 return false;
4384
4385
3/4
✓ Branch 0 taken 100 times.
✓ Branch 1 taken 200 times.
✓ Branch 2 taken 100 times.
✗ Branch 3 not taken.
300 if ( ( cheat_modifier_keys[0] > 0 && key[cheat_modifier_keys[0]] ) ||
4386
2/2
✓ Branch 0 taken 100 times.
✓ Branch 1 taken 100 times.
200 ( cheat_modifier_keys[1] > 0 && key[cheat_modifier_keys[1]] ) ||
4387
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 100 times.
100 (cheat_modifier_keys[0] <= 0 && cheat_modifier_keys[1] <= 0))
4388 {
4389
0/4
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
200 if ( ( cheat_modifier_keys[2] <= 0 || key[cheat_modifier_keys[2]] ) ||
4390 ( cheat_modifier_keys[3] > 0 && key[cheat_modifier_keys[3]] ) ||
4391 (cheat_modifier_keys[2] <= 0 && cheat_modifier_keys[3] <= 0))
4392 {
4393 return true;
4394 }
4395 }
4396 100 return false;
4397 18339918 }
4398
4399 //99:05:54, for some reason?
4400 #define OLDMAXTIME 21405240
4401 //9000:00:00, the highest even-thousand hour fitting within 32b signed. This is 375 *DAYS*.
4402 #define MAXTIME 1944000000
4403
4404 // (qr, value)
4405 403 static std::queue<std::pair<int, bool>> change_qr_queue;
4406
4407 7 void enqueue_qr_change(int qr, bool value)
4408 {
4409 7 change_qr_queue.push({qr, value});
4410 7 }
4411
4412 // During regular play, QR changes issued through `syskey` / `System` and enqueued
4413 // and soon executed here.
4414 // During playing back a replay file, the replay system adds to the same queue and
4415 // is executed here too.
4416 // This is currently only used to allow users to configure qr_HIDE_BOTTOM_8_PIXELS, but
4417 // could be later extended to all QRs (perhaps as a cheat).
4418 18340331 void process_enqueued_qr_changes()
4419 {
4420
2/2
✓ Branch 0 taken 101 times.
✓ Branch 1 taken 18340230 times.
18340331 if (replay_is_replaying())
4421 18340230 replay_do_qrs();
4422
4423
2/2
✓ Branch 0 taken 18340331 times.
✓ Branch 1 taken 7 times.
18340338 while (!change_qr_queue.empty())
4424 {
4425 28 auto [qr, value] = change_qr_queue.front();
4426 7 change_qr_queue.pop();
4427
4428 // Don't modify `quest_rules`, as that is used to store the canonical QR value which can be reset to
4429 // via system menus. Changing the unpacked array is enough to modify the engine's behavior.
4430 14 _qrs_unpacked[qr] = value;
4431 7 apply_qr_rule(qr);
4432
4433
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 1 times.
7 if (replay_is_recording())
4434 2 replay_step_qr(qr, value);
4435 }
4436 18340331 }
4437
4438 18341292 void advanceframe(bool allowwavy, bool sfxcleanup, bool allowF6Script)
4439 {
4440
1/2
✓ Branch 0 taken 18341292 times.
✗ Branch 1 not taken.
18341292 if(zcmusic!=NULL)
4441 {
4442 zcmusic_poll();
4443 }
4444 18341292 zcmixer_update(zcmixer, emusic_volume, FFCore.usr_music_volume, get_qr(qr_OLD_SCRIPT_VOLUME));
4445
4446 18341292 updatescr(allowwavy);
4447
4448 18341292 Advance=false;
4449
2/6
✗ Branch 0 not taken.
✓ Branch 1 taken 18341292 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 18341292 times.
18341292 while(Paused && !Advance && !Quit)
4450 {
4451 // have to call this, otherwise we'll get an infinite loop
4452 syskeys();
4453 if(allowF6Script)
4454 {
4455 FFCore.runF6Engine();
4456 }
4457
4458 #ifdef _WIN32
4459
4460 if(use_dwm_flush)
4461 {
4462 do_DwmFlush();
4463 }
4464
4465 #endif
4466
4467 // to keep music playing
4468 if(zcmusic!=NULL)
4469 {
4470 zcmusic_poll();
4471 }
4472
4473 update_hw_screen();
4474 }
4475
4476
2/2
✓ Branch 0 taken 18339955 times.
✓ Branch 1 taken 1337 times.
18341292 if(Quit)
4477 1337 return;
4478
4479
3/4
✓ Branch 0 taken 17828986 times.
✓ Branch 1 taken 510969 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 17828986 times.
18339955 if(Playing && game->get_time()<unsigned(get_qr(qr_GREATER_MAX_TIME) ? MAXTIME : OLDMAXTIME))
4480 17828986 game->change_time(1);
4481
4482 // Many mistakes have been make re: inputs, and we are stuck with many replays relying on those mistakes.
4483
4484 18339955 bool should_reset_down_state = !get_qr(qr_BROKEN_INPUT_DOWN_STATE);
4485
2/2
✓ Branch 0 taken 8540340 times.
✓ Branch 1 taken 9799615 times.
18339955 if (replay_version_check(0, 16))
4486 9799615 should_reset_down_state = replay_version_check(11, 16);
4487
2/2
✓ Branch 0 taken 14927826 times.
✓ Branch 1 taken 3412129 times.
18339955 if (should_reset_down_state)
4488 {
4489
2/2
✓ Branch 0 taken 61418322 times.
✓ Branch 1 taken 3412129 times.
64830451 for (int i = 0; i < ZC_CONTROL_STATES; i++)
4490 61418322 down_control_states[i] = raw_control_state[i];
4491 3412129 }
4492
4493
2/2
✓ Branch 0 taken 37 times.
✓ Branch 1 taken 18339918 times.
18339955 if (replay_is_active())
4494 {
4495
2/2
✓ Branch 0 taken 1545420 times.
✓ Branch 1 taken 16794498 times.
18339918 if (replay_version_check(3))
4496 16794498 replay_poll();
4497
4498
4/4
✓ Branch 0 taken 7478911 times.
✓ Branch 1 taken 10861007 times.
✓ Branch 2 taken 100535 times.
✓ Branch 3 taken 7378376 times.
18339918 if (replay_version_check(11) || replay_version_check(6, 8))
4499 10961542 replay_peek_input();
4500 18339918 }
4501
4502 18339955 process_enqueued_qr_changes();
4503
4504 18339955 load_control_called_this_frame = false;
4505
4506 18339955 poll_keyboard();
4507 18339955 update_keys();
4508
4509 18339955 ++frame;
4510
4511
2/2
✓ Branch 0 taken 137 times.
✓ Branch 1 taken 18339818 times.
18339955 if (replay_is_replaying())
4512 18339818 replay_do_cheats();
4513 18339955 syskeys();
4514
4515 // The mouse variables can change from the mouse thread at anytime during a frame,
4516 // so save the result at the start so that replaying is consistent.
4517 18339955 script_mouse_x = gui_mouse_x();
4518 18339955 script_mouse_y = gui_mouse_y();
4519 18339955 script_mouse_z = mouse_z;
4520 18339955 script_mouse_b = mouse_b;
4521
4522 // Cheats used via the System menu (called by syskeys) will call cheats_enqueue. syskeys
4523 // is called just above, and in the paused loop above, so the queue-and-defer-slightly
4524 // approach here means it doesn't matter which call adds the cheat.
4525 18339955 cheats_execute_queued();
4526
4527
2/2
✓ Branch 0 taken 137 times.
✓ Branch 1 taken 18339818 times.
18339955 if (replay_is_replaying())
4528 18339818 replay_peek_quit();
4529
2/2
✓ Branch 0 taken 18339910 times.
✓ Branch 1 taken 45 times.
18339955 if (GameFlags & GAMEFLAG_TRYQUIT)
4530 45 replay_step_quit(0);
4531
2/2
✓ Branch 0 taken 3322 times.
✓ Branch 1 taken 18336633 times.
18339955 if(allowF6Script)
4532 18336633 FFCore.runF6Engine();
4533
2/2
✓ Branch 0 taken 746 times.
✓ Branch 1 taken 18339209 times.
18339955 if (Quit)
4534 746 replay_step_quit(Quit);
4535
4536 #ifdef _WIN32
4537
4538 if(use_dwm_flush)
4539 {
4540 do_DwmFlush();
4541 }
4542
4543 #endif
4544
4545
2/2
✓ Branch 0 taken 208645 times.
✓ Branch 1 taken 18131310 times.
18339955 if(sfxcleanup)
4546 18131310 sfx_cleanup();
4547
4548 18339955 jit_poll();
4549
4550 #ifdef __EMSCRIPTEN__
4551 // Yield the main thread back to the browser occasionally.
4552 if (is_headless())
4553 {
4554 static int rate = 10000;
4555 static int force_yield = rate;
4556 if (force_yield++ >= rate)
4557 {
4558 force_yield = 0;
4559 emscripten_sleep(0);
4560 }
4561 }
4562 #endif
4563
4564
3/4
✓ Branch 0 taken 100 times.
✓ Branch 1 taken 18339855 times.
✓ Branch 2 taken 100 times.
✗ Branch 3 not taken.
18339955 if (zqtesting_mode && test_mode_auto_restart)
4565 {
4566 static auto last_write_time = fs::last_write_time(qstpath);
4567 static auto last_check = std::chrono::system_clock::now();
4568
4569 if (std::chrono::system_clock::now() - last_check > 200ms)
4570 {
4571 last_check = std::chrono::system_clock::now();
4572 auto write_time = fs::last_write_time(qstpath);
4573 if (last_write_time != write_time)
4574 {
4575 last_write_time = write_time;
4576 disableClickToFreeze = false;
4577 Quit = qRESET;
4578 replay_quit();
4579 }
4580 }
4581 }
4582 18341292 }
4583
4584 580 void zapout()
4585 {
4586 580 set_clip_rect(scrollbuf_old, 0, 0, scrollbuf_old->w, scrollbuf_old->h);
4587 580 blit(framebuf,scrollbuf_old,0,0,256,0,256,framebuf->h);
4588
4589 580 FFCore.runGenericPassiveEngine(SCR_TIMING_END_FRAME);
4590 580 script_drawing_commands.Clear();
4591
4592 // zap out
4593
2/2
✓ Branch 0 taken 580 times.
✓ Branch 1 taken 13920 times.
14500 for(int32_t i=1; i<=24; i++)
4594 {
4595 13920 draw_fuzzy(i);
4596 13920 advanceframe(true);
4597
4598
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 13920 times.
13920 if(Quit)
4599 {
4600 break;
4601 }
4602 13920 }
4603 580 }
4604
4605 578 void zapin()
4606 {
4607 578 FFCore.warpScriptCheck();
4608 578 draw_screen();
4609 578 set_clip_rect(scrollbuf_old, 0, 0, scrollbuf_old->w, scrollbuf_old->h);
4610 578 blit(framebuf,scrollbuf_old,0,0,256,0,256,framebuf->h);
4611
4612 // zap out
4613 578 FFCore.runGenericPassiveEngine(SCR_TIMING_END_FRAME);
4614
2/2
✓ Branch 0 taken 578 times.
✓ Branch 1 taken 13872 times.
14450 for(int32_t i=24; i>=1; i--)
4615 {
4616 13872 draw_fuzzy(i);
4617 13872 advanceframe(true);
4618
4619
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 13872 times.
13872 if(Quit)
4620 {
4621 break;
4622 }
4623 13872 }
4624 578 }
4625
4626
4627 221 void wavyout(bool showhero)
4628 {
4629 221 draw_screen(showhero);
4630
4631 221 BITMAP *wavebuf = create_bitmap_ex(8,288,framebuf->h);
4632 221 clear_to_color(wavebuf,0);
4633 221 blit(framebuf,wavebuf,0,0,16,0,framebuf->w,framebuf->h);
4634
4635 static PALETTE wavepal;
4636
4637 int32_t ofs;
4638 221 int32_t amplitude=8;
4639
4640 221 int32_t wavelength=4;
4641 221 int height = viewport.visible_height(show_bottom_8px);
4642 221 double palpos=0, palstep=4, palstop=126;
4643
4644 221 FFCore.runGenericPassiveEngine(SCR_TIMING_END_FRAME);
4645
2/2
✓ Branch 0 taken 220 times.
✓ Branch 1 taken 9257 times.
9477 for(int32_t i=0; i<height; i+=wavelength)
4646 {
4647
2/2
✓ Branch 0 taken 2369792 times.
✓ Branch 1 taken 9257 times.
2379049 for(int32_t l=0; l<256; l++)
4648 {
4649 2369792 wavepal[l].r=vbound(int32_t(RAMpal[l].r+((palpos/palstop)*(255-RAMpal[l].r))),0,255);
4650 2369792 wavepal[l].g=vbound(int32_t(RAMpal[l].g+((palpos/palstop)*(255-RAMpal[l].g))),0,255);
4651 2369792 wavepal[l].b=vbound(int32_t(RAMpal[l].b+((palpos/palstop)*(255-RAMpal[l].b))),0,255);
4652 2369792 }
4653
4654 9257 palpos+=palstep;
4655
4656
1/2
✓ Branch 0 taken 9257 times.
✗ Branch 1 not taken.
9257 if(palpos>=0)
4657 {
4658 9257 hw_palette = &wavepal;
4659 9257 update_hw_pal = true;
4660 9257 }
4661 else
4662 {
4663 hw_palette = &RAMpal;
4664 update_hw_pal = true;
4665 }
4666
4667
2/2
✓ Branch 0 taken 1555176 times.
✓ Branch 1 taken 9257 times.
1564433 for(int32_t j=0; j+playing_field_offset<framebuf->h; j++)
4668 {
4669
2/2
✓ Branch 0 taken 398125056 times.
✓ Branch 1 taken 1555176 times.
399680232 for(int32_t k=0; k<256; k++)
4670 {
4671 398125056 ofs=0;
4672
4673
4/4
✓ Branch 0 taken 194105344 times.
✓ Branch 1 taken 204019712 times.
✓ Branch 2 taken 97052672 times.
✓ Branch 3 taken 97052672 times.
398125056 if((j<i)&&(j&1))
4674 {
4675 97052672 ofs=int32_t(zc::math::Sin((double(i+j)*2*PI/height))*amplitude);
4676 97052672 }
4677
4678 398125056 framebuf->line[j+playing_field_offset][k]=wavebuf->line[j+playing_field_offset][k+ofs+16];
4679 398125056 }
4680 1555176 }
4681
4682 9257 advanceframe(true);
4683
4684
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 9256 times.
9257 if(Quit)
4685 1 break;
4686 9256 }
4687
4688 221 destroy_bitmap(wavebuf);
4689
4690 221 hw_palette = &RAMpal;
4691 221 update_hw_pal = true;
4692 221 }
4693
4694 218 void wavyin()
4695 {
4696 218 draw_screen();
4697
4698 218 BITMAP *wavebuf = create_bitmap_ex(8,288,framebuf->h);
4699 218 clear_to_color(wavebuf,0);
4700 218 blit(framebuf,wavebuf,0,0,16,0,framebuf->w,framebuf->h);
4701
4702 static PALETTE wavepal;
4703
4704 218 refreshpal=false;
4705 int32_t ofs;
4706 218 int32_t amplitude=8;
4707 218 int32_t wavelength=4;
4708 218 int height = viewport.visible_height(show_bottom_8px);
4709 218 double palpos=height, palstep=4, palstop=126;
4710
4711 218 FFCore.runGenericPassiveEngine(SCR_TIMING_END_FRAME);
4712
2/2
✓ Branch 0 taken 217 times.
✓ Branch 1 taken 9115 times.
9332 for(int32_t i=0; i<height; i+=wavelength)
4713 {
4714
2/2
✓ Branch 0 taken 2333440 times.
✓ Branch 1 taken 9115 times.
2342555 for(int32_t l=0; l<256; l++)
4715 {
4716 2333440 wavepal[l].r=vbound(int32_t(RAMpal[l].r+((palpos/palstop)*(255-RAMpal[l].r))),0,255);
4717 2333440 wavepal[l].g=vbound(int32_t(RAMpal[l].g+((palpos/palstop)*(255-RAMpal[l].g))),0,255);
4718 2333440 wavepal[l].b=vbound(int32_t(RAMpal[l].b+((palpos/palstop)*(255-RAMpal[l].b))),0,255);
4719 2333440 }
4720
4721 9115 palpos-=palstep;
4722
4723
1/2
✓ Branch 0 taken 9115 times.
✗ Branch 1 not taken.
9115 if(palpos>=0)
4724 {
4725 9115 hw_palette = &wavepal;
4726 9115 update_hw_pal = true;
4727 9115 }
4728 else
4729 {
4730 hw_palette = &RAMpal;
4731 update_hw_pal = true;
4732 }
4733
4734
2/2
✓ Branch 0 taken 1531320 times.
✓ Branch 1 taken 9115 times.
1540435 for(int32_t j=0; j+playing_field_offset<framebuf->h; j++)
4735 {
4736
2/2
✓ Branch 0 taken 392017920 times.
✓ Branch 1 taken 1531320 times.
393549240 for(int32_t k=0; k<256; k++)
4737 {
4738 392017920 ofs=0;
4739
4740
4/4
✓ Branch 0 taken 198363392 times.
✓ Branch 1 taken 193654528 times.
✓ Branch 2 taken 100348416 times.
✓ Branch 3 taken 98014976 times.
392017920 if((j<(height-1-i))&&(j&1))
4741 {
4742 98014976 ofs=int32_t(zc::math::Sin((double(i+j)*2*PI/height))*amplitude);
4743 98014976 }
4744
4745 392017920 framebuf->line[j+playing_field_offset][k]=wavebuf->line[j+playing_field_offset][k+ofs+16];
4746 392017920 }
4747 1531320 }
4748
4749 9115 advanceframe(true);
4750
4751
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 9114 times.
9115 if(Quit)
4752 1 break;
4753 9114 }
4754
4755 218 destroy_bitmap(wavebuf);
4756
4757 218 hw_palette = &RAMpal;
4758 218 update_hw_pal = true;
4759 218 }
4760
4761 4320 void blackscr(int32_t fcnt,bool showsubscr)
4762 {
4763 4320 reset_pal_cycling();
4764 4320 script_drawing_commands.Clear();
4765
4766 4320 FFCore.warpScriptCheck();
4767 4320 bool showtime = game->should_show_time();
4768
2/2
✓ Branch 0 taken 4313 times.
✓ Branch 1 taken 129157 times.
133470 while(fcnt>0)
4769 {
4770 129157 clear_bitmap(framebuf);
4771
4772
2/2
✓ Branch 0 taken 58650 times.
✓ Branch 1 taken 70507 times.
129157 if(showsubscr)
4773 {
4774 70507 put_passive_subscr(framebuf,0,0,showtime,sspUP);
4775
3/4
✓ Branch 0 taken 70507 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1290 times.
✓ Branch 3 taken 69217 times.
70507 if(get_qr(qr_SCRIPTDRAWSINWARPS) || (get_qr(qr_PASSIVE_SUBSCRIPT_RUNS_WHEN_GAME_IS_FROZEN)))
4776 {
4777 1290 do_script_draws(framebuf, origin_scr, 0, playing_field_offset);
4778 1290 }
4779 70507 }
4780
4781 129157 advanceframe(true);
4782
4783
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 129150 times.
129157 if(Quit)
4784 7 break;
4785
4786 129150 --fcnt;
4787 }
4788 4320 }
4789
4790 2694 void openscreen(int32_t shape)
4791 {
4792 2694 update_viewport();
4793 2694 is_opening_screen = true;
4794 2694 reset_pal_cycling();
4795 2694 black_opening_count=0;
4796
4797
3/4
✓ Branch 0 taken 530 times.
✓ Branch 1 taken 2164 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 530 times.
2694 if(COOLSCROLL || shape>-1)
4798 {
4799 2164 open_black_opening(HeroX()+8, (HeroY()-HeroZ()-HeroFakeZ())+8+playing_field_offset, true, shape);
4800 2164 return;
4801 }
4802 else
4803 {
4804 530 Hero.setDontDraw(true);
4805 530 show_subscreen_dmap_dots=false;
4806 530 show_subscreen_numbers=false;
4807 530 show_subscreen_life=false;
4808 }
4809
4810 530 int32_t x=128;
4811
4812 530 FFCore.warpScriptCheck();
4813
2/2
✓ Branch 0 taken 530 times.
✓ Branch 1 taken 42400 times.
42930 for(int32_t i=0; i<80; i++)
4814 {
4815 42400 draw_screen();
4816 42400 x=128-(((i*128/80)/8)*8);
4817
4818
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 42400 times.
42400 if(x>0)
4819 {
4820 42400 rectfill(framebuf,0,playing_field_offset,x,(viewport.h - 1)+playing_field_offset,0);
4821 42400 rectfill(framebuf,viewport.w-x,playing_field_offset,255,(viewport.h - 1)+playing_field_offset,0);
4822 42400 }
4823
4824 42400 advanceframe(true);
4825
4826
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 42400 times.
42400 if(Quit)
4827 {
4828 break;
4829 }
4830 42400 }
4831
4832 530 Hero.setDontDraw(false);
4833 530 show_subscreen_items=true;
4834 530 show_subscreen_dmap_dots=true;
4835 530 show_subscreen_numbers=true;
4836 530 show_subscreen_life=true;
4837 2694 }
4838
4839 14 void closescreen(int32_t shape)
4840 {
4841 14 is_opening_screen = false;
4842 14 reset_pal_cycling();
4843 14 black_opening_count=0;
4844
4845
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
14 if(COOLSCROLL || shape>-1)
4846 {
4847 14 close_black_opening(HeroX()+8, (HeroY()-HeroZ()-HeroFakeZ())+8+playing_field_offset, true, shape);
4848 14 return;
4849 }
4850 else
4851 {
4852 Hero.setDontDraw(true);
4853 show_subscreen_dmap_dots=false;
4854 show_subscreen_numbers=false;
4855 // show_subscreen_items=false;
4856 show_subscreen_life=false;
4857 }
4858
4859 int32_t x=128;
4860
4861 FFCore.warpScriptCheck();
4862 for(int32_t i=79; i>=0; --i)
4863 {
4864 draw_screen();
4865 x=128-(((i*128/80)/8)*8);
4866
4867 if(x>0)
4868 {
4869 rectfill(framebuf,0,playing_field_offset,x,(viewport.h - 1)+playing_field_offset,0);
4870 rectfill(framebuf,viewport.w-x,playing_field_offset,255,(viewport.h - 1)+playing_field_offset,0);
4871 }
4872
4873 advanceframe(true);
4874
4875 if(Quit)
4876 {
4877 break;
4878 }
4879 }
4880
4881 Hero.setDontDraw(false);
4882 show_subscreen_items=true;
4883 show_subscreen_dmap_dots=true;
4884 14 }
4885
4886 324 int32_t TriforceCount()
4887 {
4888 324 int32_t c=0;
4889
4890
2/2
✓ Branch 0 taken 2592 times.
✓ Branch 1 taken 324 times.
2916 for(int32_t i=1; i<=8; i++)
4891
2/2
✓ Branch 0 taken 484 times.
✓ Branch 1 taken 2108 times.
4700 if(game->lvlitems[i]&liTRIFORCE)
4892 2108 ++c;
4893
4894 324 return c;
4895 }
4896
4897 int32_t onCustomGame()
4898 {
4899 auto save = get_unset_save_slot();
4900 if (!save)
4901 return D_CLOSE;
4902
4903 if (prompt_for_quest_path(save->header->qstpath))
4904 {
4905 save->header->qstpath = qstpath;
4906 return D_O_K;
4907 }
4908
4909 return D_CLOSE;
4910 }
4911
4912 int32_t onContinue()
4913 {
4914 return D_CLOSE;
4915 }
4916
4917 int32_t onThrottleFPS()
4918 {
4919 Throttlefps = !Throttlefps;
4920 zc_set_config(cfg_sect,"throttlefps", (int32_t)Throttlefps);
4921 return D_O_K;
4922 }
4923
4924 int32_t onWinPosSave()
4925 {
4926 SaveWinPos = !SaveWinPos;
4927 zc_set_config(cfg_sect,"save_window_position",(int32_t)SaveWinPos);
4928 return D_O_K;
4929 }
4930 int32_t onIntegerScaling()
4931 {
4932 scaleForceInteger = !scaleForceInteger;
4933 zc_set_config("zeldadx","scaling_force_integer",(int)scaleForceInteger);
4934 return D_O_K;
4935 }
4936 int32_t onStretchGame()
4937 {
4938 stretchGame = !stretchGame;
4939 zc_set_config("zeldadx","stretch_game_area",stretchGame?1:0);
4940 return D_O_K;
4941 }
4942
4943 int32_t onClickToFreeze()
4944 {
4945 ClickToFreeze = !ClickToFreeze;
4946 zc_set_config(cfg_sect,"clicktofreeze", (int32_t)ClickToFreeze);
4947 return D_O_K;
4948 }
4949
4950 int32_t OnSaveZCConfig()
4951 {
4952 if(jwin_alert3(
4953 "Save Configuration",
4954 "Are you sure that you wish to save your present configuration settings?",
4955 "This will overwrite your prior settings!",
4956 NULL,
4957 "&Yes",
4958 "&No",
4959 NULL,
4960 'y',
4961 'n',
4962 0,
4963 get_zc_font(font_lfont)) == 1)
4964 {
4965 save_game_configs();
4966 return D_O_K;
4967 }
4968 else return D_O_K;
4969 }
4970
4971 int32_t OnnClearQuestDir()
4972 {
4973 auto current_path = fs::current_path() / "quests";
4974 if(jwin_alert3(
4975 "Clear Current Directory Cache",
4976 "Are you sure that you wish to reset where ZC Player looks for quests?",
4977 fmt::format("The new directory will be: {}", current_path.string()).c_str(),
4978 NULL,
4979 "&Yes",
4980 "&No",
4981 NULL,
4982 'y',
4983 'n',
4984 0,
4985 get_zc_font(font_lfont)) == 1)
4986 {
4987 zc_set_config("zeldadx","quest_dir","quests");
4988 flush_config_file();
4989 strcpy(qstdir,"quests");
4990 #ifdef __EMSCRIPTEN__
4991 em_sync_fs();
4992 #endif
4993 return D_O_K;
4994 }
4995 else return D_O_K;
4996 }
4997
4998 int32_t onConsole()
4999 {
5000 if ( !console_enabled )
5001 {
5002 AlertDialog("ZC Console",
5003 "Open the ZC Console?"
5004 "\nThis will display any messages logged by scripts,"
5005 " including errors.",
5006 [&](bool ret,bool)
5007 {
5008 if(ret)
5009 {
5010 FFCore.ZScriptConsole(true);
5011 }
5012 }).show();
5013 return D_O_K;
5014 }
5015 else
5016 {
5017 FFCore.ZScriptConsole(false);
5018 return D_O_K;
5019 }
5020 }
5021
5022 int32_t onClrConsoleOnReload()
5023 {
5024 clearConsoleOnReload = !clearConsoleOnReload;
5025 zc_set_config("CONSOLE","clear_console_on_reload",clearConsoleOnReload?1:0);
5026 return D_O_K;
5027 }
5028 int32_t onClrConsoleOnLoad()
5029 {
5030 clearConsoleOnLoad = !clearConsoleOnLoad;
5031 zc_set_config("CONSOLE","clear_console_on_load",clearConsoleOnLoad?1:0);
5032 return D_O_K;
5033 }
5034
5035
5036 int32_t onFrameSkip()
5037 {
5038 FrameSkip = !FrameSkip;
5039 return D_O_K;
5040 }
5041
5042 int32_t onSaveDragResize()
5043 {
5044 SaveDragResize = !SaveDragResize;
5045 zc_set_config(cfg_sect,"save_drag_resize",(int32_t)SaveDragResize);
5046 return D_O_K;
5047 }
5048
5049 int32_t onDragAspect()
5050 {
5051 DragAspect = !DragAspect;
5052 zc_set_config(cfg_sect,"drag_aspect",(int32_t)DragAspect);
5053 return D_O_K;
5054 }
5055
5056 int32_t onTransLayers()
5057 {
5058 TransLayers = !TransLayers;
5059 zc_set_config(cfg_sect,"translayers",(int32_t)TransLayers);
5060 return D_O_K;
5061 }
5062
5063 int32_t onNESquit()
5064 {
5065 NESquit = !NESquit;
5066 zc_set_config(cfg_sect,"fastquit",(int32_t)NESquit);
5067 return D_O_K;
5068 }
5069
5070 int32_t onVolKeys()
5071 {
5072 volkeys = !volkeys;
5073 zc_set_config(sfx_sect,"volkeys",(int32_t)volkeys);
5074 return D_O_K;
5075 }
5076
5077 int32_t onShowFPS()
5078 {
5079 ShowFPS = !ShowFPS;
5080 zc_set_config(cfg_sect,"showfps",(int32_t)ShowFPS);
5081 return D_O_K;
5082 }
5083
5084 int32_t onShowTime()
5085 {
5086 ShowGameTime = !ShowGameTime;
5087 zc_set_config(cfg_sect,"showtime",ShowGameTime);
5088 return D_O_K;
5089 }
5090
5091 2164110324 bool is_Fkey(int32_t k)
5092 {
5093
2/2
✓ Branch 0 taken 220079016 times.
✓ Branch 1 taken 1944031308 times.
2164110324 switch(k)
5094 {
5095 case KEY_F1:
5096 case KEY_F2:
5097 case KEY_F3:
5098 case KEY_F4:
5099 case KEY_F5:
5100 case KEY_F6:
5101 case KEY_F7:
5102 case KEY_F8:
5103 case KEY_F9:
5104 case KEY_F10:
5105 case KEY_F11:
5106 case KEY_F12:
5107 220079016 return true;
5108 }
5109
5110 1944031308 return false;
5111 2164110324 }
5112
5113 void kb_getkey(DIALOG *d);
5114
5115 //Used by all keyboard key settings dialogues.
5116 void kb_clearjoystick(DIALOG *d)
5117 {
5118 d->flags|=D_SELECTED;
5119
5120 jwin_button_proc(MSG_DRAW,d,0);
5121 jwin_draw_win(screen, (screen->w-160)/2, (screen->h-48)/2, 160, 48, FR_WIN);
5122 // text_mode(vc(11));
5123 textout_centre_ex(screen, font, "Press any key to clear", gui_bmp->w/2, gui_bmp->h/2 - 8, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5124 textout_centre_ex(screen, font, "ESC to cancel", gui_bmp->w/2, gui_bmp->h/2, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5125
5126 update_hw_screen();
5127
5128 clear_keybuf();
5129 int32_t k = next_press_key();
5130 clear_keybuf();
5131
5132 //shnarf
5133 //47=f1
5134 //59=esc
5135 // if(k>0 && k<123 && !((k>46)&&(k<60)))
5136 // *((int32_t*)d->dp3) = k;
5137 if ( k != 59 ) *((int32_t*)d->dp3) = 0;
5138
5139
5140 d->flags&=~D_SELECTED;
5141 }
5142
5143 //Clears key to 0.
5144 //Used by all keyboard key settings dialogues.
5145 void kb_clearkey(DIALOG *d);
5146
5147 int32_t d_j_clearbutton_proc(int32_t msg,DIALOG *d,int32_t c)
5148 {
5149 switch(msg)
5150 {
5151 case MSG_KEY:
5152 case MSG_CLICK:
5153
5154 kb_clearjoystick(d);
5155
5156 while(gui_mouse_b())
5157 {
5158 clear_keybuf();
5159 rest(1);
5160 }
5161
5162 return D_REDRAW;
5163 }
5164
5165 return jwin_button_proc(msg,d,c);
5166 }
5167
5168 int32_t d_kbutton_proc(int32_t msg,DIALOG *d,int32_t c);
5169 //Only used in keyboard settings dialogues to clear keys.
5170 int32_t d_k_clearbutton_proc(int32_t msg,DIALOG *d,int32_t c);
5171
5172 int32_t j_getbtn(DIALOG *d)
5173 {
5174 d->flags|=D_SELECTED;
5175 jwin_button_proc(MSG_DRAW,d,0);
5176 jwin_draw_win(screen, (screen->w-160)/2, (screen->h-48)/2, 160, 48, FR_WIN);
5177 // text_mode(vc(11));
5178 int32_t y = screen->h/2 - 12;
5179 textout_centre_ex(screen, font, "Press a button", screen->w/2, y, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5180 textout_centre_ex(screen, font, "ESC to cancel", screen->w/2, y+8, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5181 textout_centre_ex(screen, font, "SPACE to disable", screen->w/2, y+16, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5182
5183 update_hw_screen();
5184
5185 int32_t b = next_joy_input(true);
5186 if (b == -2)
5187 return D_CLOSE;
5188
5189 if(b>=0)
5190 *((int32_t*)d->dp3) = b;
5191
5192 d->flags&=~D_SELECTED;
5193
5194 return D_O_K;
5195 }
5196
5197 void j_getstick(DIALOG *d)
5198 {
5199 d->flags|=D_SELECTED;
5200 jwin_button_proc(MSG_DRAW,d,0);
5201 jwin_draw_win(screen, (screen->w-160)/2, (screen->h-48)/2, 160, 48, FR_WIN);
5202 // text_mode(vc(11));
5203 int32_t y = screen->h/2 - 12;
5204 textout_centre_ex(screen, font, "Move a stick (or DPAD)", screen->w/2, y, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5205 textout_centre_ex(screen, font, "ESC to cancel", screen->w/2, y+8, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5206 textout_centre_ex(screen, font, "SPACE to disable", screen->w/2, y+16, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5207
5208 update_hw_screen();
5209
5210 int32_t b = next_joy_input(false);
5211
5212 if(b>=0)
5213 *((int32_t*)d->dp3) = b;
5214
5215 d->flags&=~D_SELECTED;
5216 }
5217
5218 int32_t d_jbutton_proc(int32_t msg,DIALOG *d,int32_t c)
5219 {
5220 switch(msg)
5221 {
5222 case MSG_KEY:
5223 case MSG_CLICK:
5224
5225 int ret = j_getbtn(d);
5226 if (ret != D_O_K)
5227 return ret;
5228
5229 while(gui_mouse_b()) {
5230 rest(1);
5231 clear_keybuf();
5232 }
5233
5234 return D_REDRAW;
5235 }
5236
5237 return jwin_button_proc(msg,d,c);
5238 }
5239
5240 int32_t d_jstick_proc(int32_t msg,DIALOG *d,int32_t c)
5241 {
5242 switch(msg)
5243 {
5244 case MSG_KEY:
5245 case MSG_CLICK:
5246
5247 j_getstick(d);
5248
5249 while(gui_mouse_b()) {
5250 rest(1);
5251 clear_keybuf();
5252 }
5253
5254 return D_REDRAW;
5255 }
5256
5257 return jwin_button_proc(msg,d,c);
5258 }
5259
5260 //shnarf
5261 extern const char *key_str[];
5262 std::string get_keystr(int key);
5263
5264 const char *pan_str[4] = { " MONO", " 1/2", " 3/4", " FULL" };
5265
5266 static char str_a[80],str_b[80],str_s[80],str_m[80],str_l[80],str_r[80],str_p[80],str_ex1[80],str_ex2[80],str_ex3[80],str_ex4[80],
5267 str_leftmod1[80],str_leftmod2[80],str_rightmod1[80],str_rightmod2[80], str_left[80], str_right[80], str_up[80], str_down[80],
5268 str_primary_stick[80], str_secondary_stick[80];
5269
5270 int32_t d_stringloader(int32_t msg,DIALOG *d,int32_t c)
5271 {
5272 //these are here to bypass compiler warnings about unused arguments
5273 c=c;
5274
5275 if (d->w == 1)
5276 {
5277 if (!gamepad_dlg_cur_joystick || !al_get_joystick_active(gamepad_dlg_cur_joystick))
5278 {
5279 InfoDialog("ZC", "Invalid gamepad. Did it disconnect?").show();
5280 return D_CLOSE;
5281 }
5282 }
5283
5284 if(msg==MSG_DRAW)
5285 {
5286 switch(d->w)
5287 {
5288 case 0:
5289 sprintf(str_a,"%03d\n%s",Akey,key_str[Akey]);
5290 sprintf(str_b,"%03d\n%s",Bkey,key_str[Bkey]);
5291 sprintf(str_s,"%03d\n%s",Skey,key_str[Skey]);
5292 sprintf(str_l,"%03d\n%s",Lkey,key_str[Lkey]);
5293 sprintf(str_r,"%03d\n%s",Rkey,key_str[Rkey]);
5294 sprintf(str_p,"%03d\n%s",Pkey,key_str[Pkey]);
5295 sprintf(str_ex1,"%03d\n%s",Exkey1,key_str[Exkey1]);
5296 sprintf(str_ex2,"%03d\n%s",Exkey2,key_str[Exkey2]);
5297 sprintf(str_ex3,"%03d\n%s",Exkey3,key_str[Exkey3]);
5298 sprintf(str_ex4,"%03d\n%s",Exkey4,key_str[Exkey4]);
5299 sprintf(str_up,"%03d\n%s",DUkey,key_str[DUkey]);
5300 sprintf(str_down,"%03d\n%s",DDkey,key_str[DDkey]);
5301 sprintf(str_left,"%03d\n%s",DLkey,key_str[DLkey]);
5302 sprintf(str_right,"%03d\n%s",DRkey,key_str[DRkey]);
5303 sprintf(str_leftmod1,"%03d\n%s",cheat_modifier_keys[0],key_str[cheat_modifier_keys[0]]);
5304 sprintf(str_leftmod2,"%03d\n%s",cheat_modifier_keys[1],key_str[cheat_modifier_keys[1]]);
5305 sprintf(str_rightmod1,"%03d\n%s",cheat_modifier_keys[2],key_str[cheat_modifier_keys[2]]);
5306 sprintf(str_rightmod2,"%03d\n%s",cheat_modifier_keys[3],key_str[cheat_modifier_keys[3]]);
5307 break;
5308
5309 case 1:
5310 sprintf(str_a,"%03d\n%s",Abtn,joybtn_name(Abtn));
5311 sprintf(str_b,"%03d\n%s",Bbtn,joybtn_name(Bbtn));
5312 sprintf(str_s,"%03d\n%s",Sbtn,joybtn_name(Sbtn));
5313 sprintf(str_l,"%03d\n%s",Lbtn,joybtn_name(Lbtn));
5314 sprintf(str_r,"%03d\n%s",Rbtn,joybtn_name(Rbtn));
5315 sprintf(str_m,"%03d\n%s",Mbtn,joybtn_name(Mbtn));
5316 sprintf(str_p,"%03d\n%s",Pbtn,joybtn_name(Pbtn));
5317 sprintf(str_ex1,"%03d\n%s",Exbtn1,joybtn_name(Exbtn1));
5318 sprintf(str_ex2,"%03d\n%s",Exbtn2,joybtn_name(Exbtn2));
5319 sprintf(str_ex3,"%03d\n%s",Exbtn3,joybtn_name(Exbtn3));
5320 sprintf(str_ex4,"%03d\n%s",Exbtn4,joybtn_name(Exbtn4));
5321 sprintf(str_up,"%03d\n%s",DUbtn,joybtn_name(DUbtn));
5322 sprintf(str_down,"%03d\n%s",DDbtn,joybtn_name(DDbtn));
5323 sprintf(str_left,"%03d\n%s",DLbtn,joybtn_name(DLbtn));
5324 sprintf(str_right,"%03d\n%s",DRbtn,joybtn_name(DRbtn));
5325 sprintf(str_primary_stick,"%03d\n%s",js_stick_1_x_stick,joystick_name(js_stick_1_x_stick));
5326 sprintf(str_secondary_stick,"%03d\n%s",js_stick_2_x_stick,joystick_name(js_stick_2_x_stick));
5327 sprintf(str_leftmod1,"%03d\n%s",cheat_modifier_keys[0],key_str[cheat_modifier_keys[0]]);
5328 sprintf(str_leftmod2,"%03d\n%s",cheat_modifier_keys[1],key_str[cheat_modifier_keys[1]]);
5329 sprintf(str_rightmod1,"%03d\n%s",cheat_modifier_keys[2],key_str[cheat_modifier_keys[2]]);
5330 sprintf(str_rightmod2,"%03d\n%s",cheat_modifier_keys[3],key_str[cheat_modifier_keys[3]]);
5331 break;
5332
5333 case 2:
5334 sprintf(str_a," %3d",midi_volume);
5335 sprintf(str_l," %3d",emusic_volume);
5336 sprintf(str_r," %3d",sfx_volume);
5337 strcpy(str_s,pan_str[pan_style]);
5338 sprintf(str_leftmod1,"%3d\n%s",cheat_modifier_keys[0],key_str[cheat_modifier_keys[0]]);
5339 sprintf(str_leftmod2,"%3d\n%s",cheat_modifier_keys[1],key_str[cheat_modifier_keys[1]]);
5340 sprintf(str_rightmod1,"%3d\n%s",cheat_modifier_keys[2],key_str[cheat_modifier_keys[2]]);
5341 sprintf(str_rightmod2,"%3d\n%s",cheat_modifier_keys[3],key_str[cheat_modifier_keys[3]]);
5342 break;
5343 }
5344 }
5345
5346 return D_O_K;
5347 }
5348
5349 int32_t set_vol(void *dp3, int32_t d2)
5350 {
5351 switch(((int32_t*)dp3)[0])
5352 {
5353 case 0:
5354 midi_volume = zc_min(d2<<3,255);
5355 break;
5356
5357 case 1:
5358 digi_volume = zc_min(d2<<3,255);
5359 break;
5360
5361 case 2:
5362 emusic_volume = zc_min(d2<<3,255);
5363 break;
5364
5365 case 3:
5366 sfx_volume = zc_min(d2<<3,255);
5367 break;
5368 }
5369
5370 // text_mode(vc(11));
5371 textprintf_right_ex(screen,get_zc_font(font_lfont_l), ((int32_t*)dp3)[1],((int32_t*)dp3)[2],jwin_pal[jcBOXFG],jwin_pal[jcBOX]," %3d",zc_min(d2<<3,255));
5372 return D_O_K;
5373 }
5374
5375 int32_t set_pan(void *dp3, int32_t d2)
5376 {
5377 pan_style = vbound(d2,0,3);
5378 // text_mode(vc(11));
5379 textout_right_ex(screen,get_zc_font(font_lfont_l), pan_str[pan_style],((int32_t*)dp3)[1],((int32_t*)dp3)[2],jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5380 return D_O_K;
5381 }
5382
5383 static int32_t gamepad_joys_list[] =
5384 {
5385 61,
5386 -1
5387 };
5388
5389 static int32_t gamepad_btn_list[] =
5390 {
5391 6,
5392 7,8,9,10,11,12,13,14,15,16,17,
5393 18,19,20,21,22,23,24,25,26,27,28,
5394 29,30,31,32,33,34,35,36,37,38,39,
5395 -1
5396 };
5397
5398 static int32_t gamepad_dirs_list[] =
5399 {
5400 40,41,42,43,
5401 44,45,46,47,
5402 48,49,50,51,
5403 52,53,54,55,
5404 56,57,58,59,
5405 60,
5406 -1
5407 };
5408
5409 static TABPANEL gamepad_tabs[] =
5410 {
5411 // (text)
5412 { (char *)"Controllers", D_SELECTED, gamepad_joys_list, 0, NULL },
5413 { (char *)"Buttons", 0, gamepad_btn_list, 0, NULL },
5414 { (char *)"Directions", 0, gamepad_dirs_list, 0, NULL },
5415 { NULL, 0, NULL, 0, NULL }
5416 };
5417
5418 const char *joy_list(int32_t index, int32_t *list_size)
5419 {
5420 if (index == -1)
5421 {
5422 *list_size = al_get_num_joysticks();
5423 return NULL;
5424 }
5425
5426 ALLEGRO_JOYSTICK* joy = al_get_joystick(index);
5427 if (!joy)
5428 {
5429 return "?";
5430 }
5431
5432 return al_get_joystick_name(joy);
5433 }
5434
5435 403 static ListData joy__list(joy_list, &font);
5436
5437 static int32_t d_joylist_proc(int32_t msg,DIALOG *d,int32_t c)
5438 {
5439 int32_t d2 = d->d2;
5440 int32_t ret = jwin_droplist_proc(msg,d,c);
5441
5442 if(d2!=d->d2)
5443 {
5444 joystick_index = d->d2;
5445 ret |= D_REDRAW_ALL;
5446 }
5447
5448 return ret;
5449 }
5450
5451 static DIALOG gamepad_dlg[] =
5452 {
5453 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3)
5454 { jwin_win_proc, 8, 24, 304, 256, 0, 0, 0, D_EXIT, 0, 0, (void *) "Gamepad Controls", NULL, NULL },
5455 { jwin_tab_proc, 8+4, 24+23,304-8,256-52,vc(0), vc(15), 0, 0, 0, 0, (void *) gamepad_tabs, NULL, (void *)gamepad_dlg },
5456 { d_stringloader, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5457 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5458 { jwin_button_proc, 90, 254, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
5459 { jwin_button_proc, 170, 254, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
5460 // 6
5461 { d_dummy_proc, 14, 61, 294, 192, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5462 // 7
5463 { jwin_ctext_proc, 92, 92-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_a, NULL, NULL },
5464 { jwin_ctext_proc, 92, 120-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_b, NULL, NULL },
5465 { jwin_ctext_proc, 92, 148-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_s, NULL, NULL },
5466 { jwin_ctext_proc, 92, 180-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex1, NULL, NULL },
5467 { jwin_ctext_proc, 92, 212-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex3, NULL, NULL },
5468 { jwin_ctext_proc, 237, 92-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_l, NULL, NULL },
5469 { jwin_ctext_proc, 237, 120-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_r, NULL, NULL },
5470 { jwin_ctext_proc, 237, 148-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_p, NULL, NULL },
5471 { jwin_ctext_proc, 237, 180-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex2, NULL, NULL },
5472 { jwin_ctext_proc, 237, 212-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex4, NULL, NULL },
5473 { jwin_ctext_proc, 92, 244-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_m, NULL, NULL },
5474 // 18
5475 { d_jbutton_proc, 22, 90-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "A", NULL, &Abtn},
5476 { d_jbutton_proc, 22, 118-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "B", NULL, &Bbtn},
5477 { d_jbutton_proc, 22, 146-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Start", NULL, &Sbtn},
5478 { d_jbutton_proc, 22, 178-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "X (EX1)", NULL, &Exbtn1},
5479 { d_jbutton_proc, 22, 210-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "EX3", NULL, &Exbtn3},
5480 { d_jbutton_proc, 167, 90-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "L", NULL, &Lbtn},
5481 { d_jbutton_proc, 167, 118-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "R", NULL, &Rbtn},
5482 { d_jbutton_proc, 167, 146-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Map", NULL, &Pbtn},
5483 { d_jbutton_proc, 167, 178-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Y (EX2)", NULL, &Exbtn2},
5484 { d_jbutton_proc, 167, 210-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "EX4", NULL, &Exbtn4},
5485 { d_jbutton_proc, 22, 242-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Menu", NULL, &Mbtn},
5486 // 29
5487 { d_j_clearbutton_proc, 22+91, 90-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Abtn},
5488 { d_j_clearbutton_proc, 22+91, 118-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Bbtn},
5489 { d_j_clearbutton_proc, 22+91, 146-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Sbtn},
5490 { d_j_clearbutton_proc, 22+91, 178-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exbtn1},
5491 { d_j_clearbutton_proc, 22+91, 210-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exbtn3},
5492 { d_j_clearbutton_proc, 167+91, 90-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Lbtn},
5493 { d_j_clearbutton_proc, 167+91, 118-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Rbtn},
5494 { d_j_clearbutton_proc, 167+91, 146-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Pbtn},
5495 { d_j_clearbutton_proc, 167+91, 178-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exbtn2},
5496 { d_j_clearbutton_proc, 167+91, 210-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exbtn4},
5497 { d_j_clearbutton_proc, 22+91, 242-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Mbtn},
5498 // 40
5499 { jwin_frame_proc, 14, 62, 147, 80, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5500 { jwin_frame_proc, 159, 62, 147, 80, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5501 { jwin_text_proc, 30, 68, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Vertical", NULL, NULL },
5502 { jwin_text_proc, 175, 68, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Horizontal", NULL, NULL },
5503 // 44
5504 { jwin_text_proc, 92, 84, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_up, NULL, NULL },
5505 { jwin_text_proc, 92, 112, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_down, NULL, NULL },
5506 { jwin_text_proc, 237, 84, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_left, NULL, NULL },
5507 { jwin_text_proc, 237, 112, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_right, NULL, NULL },
5508 // 48
5509 { d_jbutton_proc, 22, 82, 61, 21, vc(14), vc(11), 0, 0, 0, 0, (void *) "Up", NULL, &DUbtn },
5510 { d_jbutton_proc, 22, 110, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Down", NULL, &DDbtn },
5511 { d_jbutton_proc, 167, 82, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Left", NULL, &DLbtn },
5512 { d_jbutton_proc, 167, 110, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Right", NULL, &DRbtn },
5513 // 52
5514 { d_j_clearbutton_proc, 22+91, 82, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DUbtn},
5515 { d_j_clearbutton_proc, 22+91, 110, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DDbtn},
5516 { d_j_clearbutton_proc, 167+91, 82, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DLbtn},
5517 { d_j_clearbutton_proc, 167+91, 110, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DRbtn},
5518 // 56
5519 { jwin_check_proc, 22, 150, 147, 8, vc(14), vc(1), 0, 0, 1, 0, (void *) "Primary: Use Analog Stick (Ignore above and use below instead)", NULL, NULL },
5520 { d_jstick_proc, 22, 165, 61, 21, vc(14), vc(11), 0, 0, 0, 0, (void *) "Primary", NULL, &js_stick_1_x_stick },
5521 { d_jstick_proc, 22, 195, 61, 21, vc(14), vc(11), 0, 0, 0, 0, (void *) "Secondary", NULL, &js_stick_2_x_stick },
5522 { jwin_text_proc, 90, 165, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_primary_stick, NULL, NULL },
5523 { jwin_text_proc, 90, 195, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_secondary_stick, NULL, NULL },
5524
5525 // 61
5526 { d_joylist_proc, 22, 62, 150, 16, 0, 0, 0, 0, 0, 0, (void *) &joy__list, NULL, NULL },
5527
5528 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
5529 };
5530
5531 static int32_t keyboard_keys_list[] =
5532 {
5533 6,7,8,9,10,
5534 11,12,13,14,15,16,17,18,19,20,
5535 21,22,23,24,25,26,27,28,29,30,
5536 31,32,33,34,35,36,37,38,39,40,
5537 -1
5538 };
5539
5540 static int32_t keyboard_dirs_list[] =
5541 {
5542 41,42,43,44,
5543 45,46,47,48,
5544 49,50,51,52,
5545 53,54,55,56,
5546 -1
5547 };
5548
5549 static int32_t keyboard_mods_list[] =
5550 {
5551 57,58,59,60,
5552 61,62,63,64,
5553 65,66,67,68,
5554 69,70,71,72,
5555 -1
5556 };
5557
5558 static TABPANEL keyboard_control_tabs[] =
5559 {
5560 // (text)
5561 { (char *)"Keys", D_SELECTED, keyboard_keys_list, 0, NULL },
5562 { (char *)"Directions", 0, keyboard_dirs_list, 0, NULL },
5563 { (char *)"Cheat Mods", 0, keyboard_mods_list, 0, NULL },
5564 { NULL, 0, NULL, 0, NULL }
5565 };
5566
5567 static DIALOG keyboard_control_dlg[] =
5568 {
5569 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3)
5570 { jwin_win_proc, 8, 39, 304, 240, 0, 0, 0, D_EXIT, 0, 0, (void *) "Keyboard Controls", NULL, NULL },
5571 { jwin_tab_proc, 8+4, 39+23,304-8,240-56,vc(0), vc(15), 0, 0, 0, 0, (void *) keyboard_control_tabs, NULL, (void *)keyboard_control_dlg },
5572 { d_stringloader, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5573 { jwin_button_proc, 90, 254, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
5574 { jwin_button_proc, 170, 254, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
5575 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5576 // Keys
5577 // 6
5578 { jwin_frame_proc, 14, 80, 148, 105, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5579 { jwin_frame_proc, 158, 80, 148, 105, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5580 { jwin_frame_proc, 14, 181, 292, 67, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5581 { jwin_text_proc, 30, 86, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Standard", NULL, NULL },
5582 { jwin_text_proc, 175, 86, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Extended", NULL, NULL },
5583 // 11
5584 { jwin_text_proc, 92-4, 102, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_a, NULL, NULL },
5585 { jwin_text_proc, 92-4, 130, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_b, NULL, NULL },
5586 { jwin_text_proc, 92-4, 158, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_s, NULL, NULL },
5587 { jwin_text_proc, 92-4, 190, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex1, NULL, NULL },
5588 { jwin_text_proc, 92-4, 222, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex3, NULL, NULL },
5589 { jwin_text_proc, 237-4, 102, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_l, NULL, NULL },
5590 { jwin_text_proc, 237-4, 130, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_r, NULL, NULL },
5591 { jwin_text_proc, 237-4, 158, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_p, NULL, NULL },
5592 { jwin_text_proc, 237-4, 190, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex2, NULL, NULL },
5593 { jwin_text_proc, 237-4, 222, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex4, NULL, NULL },
5594 // 21
5595 { d_kbutton_proc, 22, 100, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "A", NULL, &Akey},
5596 { d_kbutton_proc, 22, 128, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "B", NULL, &Bkey},
5597 { d_kbutton_proc, 22, 156, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Start", NULL, &Skey},
5598 { d_kbutton_proc, 22, 188, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "X (EX1)", NULL, &Exkey1},
5599 { d_kbutton_proc, 22, 220, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "EX3", NULL, &Exkey3},
5600 { d_kbutton_proc, 167, 100, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "L", NULL, &Lkey},
5601 { d_kbutton_proc, 167, 128, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "R", NULL, &Rkey},
5602 { d_kbutton_proc, 167, 156, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Map", NULL, &Pkey},
5603 { d_kbutton_proc, 167, 188, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Y (EX2)", NULL, &Exkey2},
5604 { d_kbutton_proc, 167, 220, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "EX4", NULL, &Exkey4},
5605 // 31
5606 { d_k_clearbutton_proc, 22+91, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Akey},
5607 { d_k_clearbutton_proc, 22+91, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Bkey},
5608 { d_k_clearbutton_proc, 22+91, 156, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Skey},
5609 { d_k_clearbutton_proc, 22+91, 188, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exkey1},
5610 { d_k_clearbutton_proc, 22+91, 220, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exkey3},
5611 { d_k_clearbutton_proc, 167+91, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Lkey},
5612 { d_k_clearbutton_proc, 167+91, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Rkey},
5613 { d_k_clearbutton_proc, 167+91, 156, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Pkey},
5614 { d_k_clearbutton_proc, 167+91, 188, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exkey2},
5615 { d_k_clearbutton_proc, 167+91, 220, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exkey4},
5616 // Dirs
5617 // 41
5618 { jwin_frame_proc, 14, 80, 147, 80, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5619 { jwin_frame_proc, 159, 80, 147, 80, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5620 { jwin_text_proc, 30, 86, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Vertical", NULL, NULL },
5621 { jwin_text_proc, 175, 86, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Horizontal", NULL, NULL },
5622 // 45
5623 { jwin_text_proc, 92-4, 102, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_up, NULL, NULL },
5624 { jwin_text_proc, 92-4, 130, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_down, NULL, NULL },
5625 { jwin_text_proc, 237-4, 102, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_left, NULL, NULL },
5626 { jwin_text_proc, 237-4, 130, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_right, NULL, NULL },
5627 // 49
5628 { d_kbutton_proc, 22, 100, 61, 21, vc(14), vc(11), 0, 0, 0, 0, (void *) "Up", NULL, &DUkey},
5629 { d_kbutton_proc, 22, 128, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Down", NULL, &DDkey},
5630 { d_kbutton_proc, 167, 100, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Left", NULL, &DLkey},
5631 { d_kbutton_proc, 167, 128, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Right", NULL, &DRkey},
5632 // 53
5633 { d_k_clearbutton_proc, 22+91, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DUkey},
5634 { d_k_clearbutton_proc, 22+91, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DDkey},
5635 { d_k_clearbutton_proc, 167+91, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DLkey},
5636 { d_k_clearbutton_proc, 167+91, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DRkey},
5637 // Mods
5638 // 57
5639 { jwin_frame_proc, 14, 80, 148, 140-58, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5640 { jwin_frame_proc, 158, 80, 148, 140-58, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5641 { jwin_text_proc, 30, 86, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Left", NULL, NULL },
5642 { jwin_text_proc, 175, 86, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Right", NULL, NULL },
5643 // 61
5644 { jwin_text_proc, 92-26, 101, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_leftmod1, NULL, NULL },
5645 { jwin_text_proc, 92-26, 129, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_rightmod1, NULL, NULL },
5646 { jwin_text_proc, 237-4-22,101, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_leftmod2, NULL, NULL },
5647 { jwin_text_proc, 237-4-22,129, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_rightmod2, NULL, NULL },
5648 // 65
5649 { d_kbutton_proc, 22, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Main", NULL, &cheat_modifier_keys[0]},
5650 { d_kbutton_proc, 22, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Second", NULL, &cheat_modifier_keys[2]},
5651 { d_kbutton_proc, 167, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Main", NULL, &cheat_modifier_keys[1]},
5652 { d_kbutton_proc, 167, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Second", NULL, &cheat_modifier_keys[3]},
5653 // 69
5654 { d_k_clearbutton_proc, 22+91, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &cheat_modifier_keys[0]},
5655 { d_k_clearbutton_proc, 22+91, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &cheat_modifier_keys[2]},
5656 { d_k_clearbutton_proc, 167+91, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &cheat_modifier_keys[1]},
5657 { d_k_clearbutton_proc, 167+91, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &cheat_modifier_keys[3]},
5658 // 73
5659 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
5660 };
5661
5662 int32_t midi_dp[3] = {0,0,0};
5663 int32_t emus_dp[3] = {2,0,0};
5664 int32_t sfx_dp[3] = {3,0,0};
5665 int32_t pan_dp[3] = {0,0,0};
5666
5667 static DIALOG sound_dlg[] =
5668 {
5669 //(dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3)
5670 403 { jwin_win_proc, 0, 0, 320, 178, 0, 0, 0, D_EXIT, 0, 0, (void *) "Sound Settings", NULL, NULL },
5671 403 { d_stringloader, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5672 403 { jwin_button_proc, 58, 148, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
5673 403 { jwin_button_proc, 138, 148, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
5674 403 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5675 403 { jwin_frame_proc, 10, 28, 300, 112, 0, 0, 0, 0, FR_ETCHED, 0, NULL, NULL, NULL },
5676 403 { jwin_rtext_proc, 190, 40, 40, 8, vc(7), vc(11), 0, 0, 0, 0, (void *) str_a, NULL, NULL },
5677 403 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5678 403 { jwin_rtext_proc, 190, 56, 40, 8, vc(7), vc(11), 0, 0, 0, 0, (void *) str_l, NULL, NULL },
5679 403 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5680 // 10
5681 403 { jwin_rtext_proc, 190, 72, 40, 8, vc(7), vc(11), 0, 0, 0, 0, (void *) str_r, NULL, NULL },
5682 403 { jwin_rtext_proc, 190, 88, 40, 8, vc(7), vc(11), 0, 0, 0, 0, (void *) str_s, NULL, NULL },
5683 403 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5684 403 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5685 403 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5686 403 { jwin_slider_proc, 196, 40, 96, 8, vc(0), jwin_pal[jcBOX], 0, 0, 32, 0, NULL, (void *) set_vol, midi_dp },
5687 403 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5688 403 { jwin_slider_proc, 196, 56, 96, 8, vc(0), jwin_pal[jcBOX], 0, 0, 32, 0, NULL, (void *) set_vol, emus_dp },
5689 403 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5690 403 { jwin_slider_proc, 196, 72, 96, 8, vc(0), jwin_pal[jcBOX], 0, 0, 32, 0, NULL, (void *) set_vol, sfx_dp },
5691 //20
5692 403 { jwin_slider_proc, 196, 88, 96, 8, vc(0), jwin_pal[jcBOX], 0, 0, 3, 0, NULL, (void *) set_pan, pan_dp },
5693 403 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5694 403 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5695 403 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5696 403 { jwin_text_proc, 17, 40, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "MIDI Volume", NULL, NULL },
5697 403 { jwin_text_proc, 17, 56, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Music Volume (Enhanced Music)", NULL, NULL },
5698 403 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5699 403 { jwin_text_proc, 17, 72, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "SFX Volume", NULL, NULL },
5700 403 { jwin_text_proc, 17, 88, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "SFX Pan", NULL, NULL },
5701 403 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5702 //30
5703 403 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5704 403 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5705 403 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5706 };
5707
5708 char zc_builddate[80];
5709 char zc_aboutstr[80];
5710
5711 static DIALOG about_dlg[] =
5712 {
5713 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */
5714 { jwin_win_proc, 68, 52, 184, 154, 0, 0, 0, D_EXIT, 0, 0, (void *) "About", NULL, NULL },
5715 { jwin_button_proc, 140, 176, 41, 21, vc(14), 0, 0, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
5716 { jwin_ctext_proc, 160, 84, 0, 8, vc(0), vc(11), 0, 0, 0, 0, zc_aboutstr, NULL, NULL },
5717 { jwin_ctext_proc, 160, 92, 0, 8, vc(0) , vc(11), 0, 0, 0, 0, str_s, NULL, NULL },
5718 { jwin_ctext_proc, 160, 100, 0, 8, vc(0) , vc(11), 0, 0, 0, 0, zc_builddate, NULL, NULL },
5719 { jwin_text_proc, 88, 124, 140, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Coded by:", NULL, NULL },
5720 { jwin_text_proc, 88, 132, 140, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) " Phantom Menace", NULL, NULL },
5721 { jwin_text_proc, 88, 144, 140, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Produced by:", NULL, NULL },
5722 { jwin_text_proc, 88, 152, 140, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) " Armageddon Games", NULL, NULL },
5723 { jwin_frame_proc, 80, 117, 160, 50, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5724 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5725 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
5726 };
5727
5728
5729 static DIALOG quest_dlg[] =
5730 {
5731 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */
5732 { jwin_win_proc, 68, 25, 184, 190, 0, 0, 0, D_EXIT, 0, 0, (void *) "Quest Info", NULL, NULL },
5733 { jwin_edit_proc, 84, 54, 152, 16, 0, 0, 0, D_READONLY, 100, 0, NULL, NULL, NULL },
5734 { jwin_text_proc, 89, 84, 141, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Number:", NULL, NULL },
5735 { jwin_text_proc, 152, 84, 24, 8, vc(7), vc(11), 0, 0, 0, 0, str_a, NULL, NULL },
5736 { jwin_text_proc, 89, 94, 141, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Version:", NULL, NULL },
5737 { jwin_text_proc, 160, 94, 64, 8, vc(7), vc(11), 0, 0, 0, 0, header_version_nul_term, NULL, NULL },
5738 { jwin_text_proc, 89, 104, 141, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "ZQ Version:", NULL, NULL },
5739 { jwin_text_proc, 130, 104, 64, 8, vc(7), vc(11), 0, 0, 0, 0, str_s, NULL, NULL },
5740 { jwin_text_proc, 84, 126, 80, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Title:", NULL, NULL },
5741 { jwin_textbox_proc, 84, 136, 152, 24, 0, 0, 0, 0, 0, 0, QHeader.title, NULL, NULL },
5742 { jwin_text_proc, 84, 168, 80, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Author:", NULL, NULL },
5743 { jwin_textbox_proc, 84, 178, 152, 24, 0, 0, 0, 0, 0, 0, QHeader.author, NULL, NULL },
5744 { jwin_frame_proc, 84, 79, 152, 38, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5745 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5746 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
5747 };
5748
5749 static DIALOG triforce_dlg[] =
5750 {
5751 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
5752 { jwin_win_proc, 72, 64, 177, 105, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Triforce Pieces", NULL, NULL },
5753 // 1
5754 { jwin_check_proc, 129, 94, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "1", NULL, NULL },
5755 { jwin_check_proc, 129, 104, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "2", NULL, NULL },
5756 { jwin_check_proc, 129, 114, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "3", NULL, NULL },
5757 { jwin_check_proc, 129, 124, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "4", NULL, NULL },
5758 { jwin_check_proc, 172, 94, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "5", NULL, NULL },
5759 { jwin_check_proc, 172, 104, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "6", NULL, NULL },
5760 { jwin_check_proc, 172, 114, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "7", NULL, NULL },
5761 { jwin_check_proc, 172, 124, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "8", NULL, NULL },
5762 // 9
5763 { jwin_button_proc, 90, 144, 61, 21, vc(0), vc(11), 'k', D_EXIT, 0, 0, (void *) "O&K", NULL, NULL },
5764 { jwin_button_proc, 170, 144, 61, 21, vc(0), vc(11), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
5765 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5766 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
5767 };
5768
5769 int32_t onToggleRecordingNewSaves()
5770 {
5771 if (zc_get_config("zeldadx", "replay_new_saves", false))
5772 {
5773 zc_set_config("zeldadx", "replay_new_saves", false);
5774 }
5775 else
5776 {
5777 zc_set_config("zeldadx", "replay_new_saves", true);
5778 jwin_alert("Recording", "Newly created saves will be recorded and written to a replay file.",
5779 NULL,NULL,"OK",NULL,13,27,get_zc_font(font_lfont));
5780 }
5781 return D_O_K;
5782 }
5783
5784 #ifdef HAS_CURL
5785 int32_t onToggleAutoUploadReplays()
5786 {
5787 if (zc_get_config("zeldadx", "replay_upload", false))
5788 {
5789 zc_set_config("zeldadx", "replay_upload", false);
5790 }
5791 else
5792 {
5793 zc_set_config("zeldadx", "replay_upload", true);
5794 jwin_alert("Replays", "Replays will be automatically uploaded. This helps development by",
5795 " preventing bugs and simplifying bug reports.",
5796 "Upload will happen no more than once a week when closing ZC",
5797 "OK",NULL,13,27,get_zc_font(font_lfont));
5798
5799 if (!zc_get_config("zeldadx", "replay_new_saves", false))
5800 onToggleRecordingNewSaves();
5801 }
5802 return D_O_K;
5803 }
5804
5805 int32_t onUploadReplays()
5806 {
5807 if(jwin_alert3(
5808 "Upload replays",
5809 "Upload your replays now to assist in development?",
5810 NULL,
5811 NULL,
5812 "&Yes",
5813 "&No",
5814 NULL,
5815 'y',
5816 'n',
5817 0,
5818 get_zc_font(font_lfont)) == 1)
5819 {
5820 int num_uploaded = replay_upload();
5821 jwin_alert("Upload replays", fmt::format("Uploaded {} replays", num_uploaded).c_str(),
5822 NULL,NULL,"OK",NULL,13,27,get_zc_font(font_lfont));
5823 }
5824 return D_O_K;
5825 }
5826
5827 int32_t onClearUploadCache()
5828 {
5829 if(jwin_alert3(
5830 "Upload replays",
5831 "Clear the upload cache?",
5832 "This simply deletes replays/state.json. There's no harm in doing this, but",
5833 "likely is not necessary.",
5834 "&Yes",
5835 "&No",
5836 NULL,
5837 'y',
5838 'n',
5839 0,
5840 get_zc_font(font_lfont)) == 1)
5841 {
5842 replay_upload_clear_cache();
5843 }
5844 return D_O_K;
5845 }
5846 #endif
5847
5848 int32_t onToggleSnapshotAllFrames()
5849 {
5850 replay_set_snapshot_all_frames(!replay_is_snapshot_all_frames());
5851 return D_O_K;
5852 }
5853
5854 int32_t onStopReplayOrRecord()
5855 {
5856 if (replay_is_replaying())
5857 {
5858 replay_quit();
5859 }
5860 else if (replay_get_mode() == ReplayMode::Record)
5861 {
5862 if (!replay_get_meta_bool("test_mode"))
5863 {
5864 jwin_alert("Recording", "You cannot stop recording a save file.",
5865 NULL,NULL,"OK",NULL,13,27,get_zc_font(font_lfont));
5866 return D_CLOSE;
5867 }
5868
5869 if (jwin_alert("Stop Recording",
5870 "Save replay to disk and stop recording?",
5871 "This will stop the recording.",
5872 NULL,
5873 "Yes","No",13,27,get_zc_font(font_lfont)) != 1)
5874 return D_CLOSE;
5875
5876 replay_save();
5877 replay_stop();
5878 }
5879 return D_O_K;
5880 }
5881
5882 static int32_t handle_on_load_replay(ReplayMode mode)
5883 {
5884 bool ctrl = CHECK_CTRL_CMD;
5885 if (Playing)
5886 {
5887 if (jwin_alert("Replay - Warning!",
5888 "Loading a replay will exit the current game.",
5889 "All unsaved progress will be lost.",
5890 "Do you wish to continue?",
5891 "Yes","No",13,27,get_zc_font(font_lfont)) != 1)
5892 return D_CLOSE;
5893 }
5894
5895 std::string mode_string = replay_mode_to_string(mode);
5896 mode_string[0] = std::toupper(mode_string[0]);
5897
5898 std::string line_1 = "Select a replay file to play back.";
5899 std::string line_2 = "You won't be able to save, and it won't effect existing saves.";
5900 std::string line_3 = "You can stop the replay and take over manually any time.";
5901 if (mode == ReplayMode::Update)
5902 {
5903 line_1 = "Select a replay file to update.";
5904 line_2 = "WARNING: be sure to back up the zplay file";
5905 line_3 = "and verify that the updated replay works as expected!";
5906 }
5907
5908 if (jwin_alert(mode_string.c_str(),
5909 line_1.c_str(),
5910 line_2.c_str(),
5911 line_3.c_str(),
5912 "OK","Nevermind",13,27,get_zc_font(font_lfont)) == 1)
5913 {
5914 std::string replay_path = "replays/";
5915 if(ctrl && devpwd())
5916 replay_path = "../../tests/replays/";
5917 std::string prompt = fmt::format("Load Replay ({})", REPLAY_EXTENSION);
5918 if (auto result = prompt_for_existing_file(prompt, REPLAY_EXTENSION, nullptr, replay_path))
5919 replay_path = *result;
5920 else
5921 return D_CLOSE;
5922
5923 replay_quit();
5924 load_replay_file_deferred(mode, replay_path);
5925 Quit = qRESET;
5926 return D_CLOSE;
5927 }
5928 return D_O_K;
5929 }
5930
5931 int32_t onLoadReplay()
5932 {
5933 return handle_on_load_replay(ReplayMode::Replay);
5934 }
5935
5936 int32_t onLoadReplayAssert()
5937 {
5938 return handle_on_load_replay(ReplayMode::Assert);
5939 }
5940
5941 int32_t onLoadReplayUpdate()
5942 {
5943 return handle_on_load_replay(ReplayMode::Update);
5944 }
5945
5946 int32_t onSaveReplay()
5947 {
5948 if (replay_get_mode() == ReplayMode::Record)
5949 {
5950 if (!replay_get_meta_bool("test_mode"))
5951 {
5952 if (jwin_alert("Save Replay",
5953 "This will save a copy of the replay up to this point.",
5954 "The official replay file will be untouched.",
5955 "Do you wish to continue?",
5956 "Yes","No",13,27,get_zc_font(font_lfont)) != 1)
5957 {
5958 return D_CLOSE;
5959 }
5960
5961 std::string replay_path = replay_get_replay_path().string();
5962 std::string prompt = fmt::format("Save Replay ({})", REPLAY_EXTENSION);
5963 if (auto result = prompt_for_new_file(prompt, REPLAY_EXTENSION, nullptr, replay_path))
5964 replay_path = *result;
5965 else
5966 return D_CLOSE;
5967
5968 if (fileexists(replay_path.c_str()))
5969 {
5970 jwin_alert("Save Replay", "You cannot overwrite an existing file.",
5971 NULL,NULL,"OK",NULL,13,27,get_zc_font(font_lfont));
5972 return D_CLOSE;
5973 }
5974
5975 replay_save(replay_path);
5976 }
5977 else
5978 {
5979 replay_save();
5980 }
5981 }
5982 return D_O_K;
5983 }
5984
5985 enum
5986 {
5987 MENUID_REPLAY_RECORDNEW,
5988 MENUID_REPLAY_STOP,
5989 MENUID_REPLAY_SAVE,
5990 MENUID_REPLAY_SNAP_ALL,
5991 MENUID_REPLAY_AUTOUPLOAD,
5992 MENUID_REPLAY_UPLOAD,
5993 MENUID_REPLAY_CLEARUPLOADCACHE,
5994 };
5995
1/4
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
403 static NewMenu replay_menu
5996 5239 {
5997
2/4
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 403 times.
✗ Branch 3 not taken.
403 { "Record new saves", onToggleRecordingNewSaves, MENUID_REPLAY_RECORDNEW },
5998
2/4
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 403 times.
✗ Branch 3 not taken.
403 {},
5999
2/4
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 403 times.
✗ Branch 3 not taken.
403 { "Stop replay", onStopReplayOrRecord, MENUID_REPLAY_STOP },
6000
2/4
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 403 times.
✗ Branch 3 not taken.
403 { "Load replay", onLoadReplay },
6001
2/4
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 403 times.
✗ Branch 3 not taken.
403 { "Load replay (assert)", onLoadReplayAssert },
6002
2/4
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 403 times.
✗ Branch 3 not taken.
403 { "Load replay (update)", onLoadReplayUpdate },
6003
2/4
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 403 times.
✗ Branch 3 not taken.
403 { "Save replay", onSaveReplay, MENUID_REPLAY_SAVE },
6004
2/4
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 403 times.
✗ Branch 3 not taken.
403 { "Snapshot all frames", onToggleSnapshotAllFrames, MENUID_REPLAY_SNAP_ALL },
6005 #ifdef HAS_CURL
6006
2/4
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 403 times.
✗ Branch 3 not taken.
403 {},
6007
2/4
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 403 times.
✗ Branch 3 not taken.
403 { "Auto upload replays", onToggleAutoUploadReplays, MENUID_REPLAY_AUTOUPLOAD },
6008
2/4
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 403 times.
✗ Branch 3 not taken.
403 { "Upload replays", onUploadReplays, MENUID_REPLAY_UPLOAD },
6009
2/4
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 403 times.
✗ Branch 3 not taken.
403 { "Clear upload cache", onClearUploadCache, MENUID_REPLAY_CLEARUPLOADCACHE },
6010 #endif
6011 };
6012
6013 static DIALOG credits_dlg[] =
6014 {
6015 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */
6016 { jwin_win_proc, 40, 38, 241, 173, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "ZQuest Classic Credits", NULL, NULL },
6017 { jwin_frame_proc, 47, 65, 227, 115, vc(15), vc(1), 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
6018 { d_bitmap_proc, 49, 67, 222, 110, vc(15), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
6019 { jwin_button_proc, 140, 184, 41, 21, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
6020 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
6021 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
6022 };
6023
6024 403 static ListData dmap_list(dmaplist, &font);
6025
6026 static DIALOG goto_dlg[] =
6027 {
6028 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */
6029 { jwin_win_proc, 48, 25, 205, 100, 0, 0, 0, D_EXIT, 0, 0, (void *) "Goto Location", NULL, NULL },
6030 { jwin_button_proc, 90, 176-78, 61, 21, vc(14), 0, 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
6031 { jwin_button_proc, 170, 176-78, 61, 21, vc(14), 0, 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
6032 { jwin_text_proc, 55, 129-75, 80, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "DMap:", NULL, NULL },
6033 { jwin_droplist_proc, 88, 126-75, 160, 16, 0, 0, 0, 0, 0, 0, (void *) &dmap_list, NULL, NULL },
6034 { jwin_text_proc, 55, 149-75, 80, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Screen:", NULL, NULL },
6035 { jwin_edit_proc, 132, 146-75, 91, 16, 0, 0, 0, 0, 2, 0, NULL, NULL, NULL },
6036 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
6037 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
6038 };
6039
6040 int32_t onGoTo()
6041 {
6042 bool music = false;
6043 music = music;
6044 sprintf(cheat_goto_screen_str,"%X",cheat_goto_screen);
6045
6046 goto_dlg[0].dp2=get_zc_font(font_lfont);
6047 goto_dlg[4].d2=cheat_goto_dmap;
6048 goto_dlg[6].dp=cheat_goto_screen_str;
6049
6050 clear_keybuf();
6051
6052 large_dialog(goto_dlg);
6053
6054 if(do_zqdialog(goto_dlg,4)==1)
6055 {
6056 int dmap = goto_dlg[4].d2;
6057 int screen = zc_xtoi(cheat_goto_screen_str);
6058 int adjusted_screen = screen + DMaps[dmap].xoff;
6059 if (adjusted_screen < 0 || adjusted_screen >= 128)
6060 {
6061 InfoDialog("Invalid screen", fmt::format("The screen {:02X} is out of bounds.", adjusted_screen)).show();
6062 }
6063 else
6064 {
6065 cheats_enqueue(Cheat::GoTo, dmap, screen);
6066 }
6067 };
6068
6069 return D_O_K;
6070 }
6071
6072 int32_t onGoToComplete()
6073 {
6074 if(!Playing)
6075 {
6076 return D_O_K;
6077 }
6078
6079 enter_sys_pal();
6080 music_pause();
6081 pause_all_sfx();
6082 onGoTo();
6083 eat_buttons();
6084
6085 zc_readrawkey(KEY_ESC);
6086
6087 exit_sys_pal();
6088 music_resume();
6089 resume_all_sfx();
6090 return D_O_K;
6091 }
6092
6093 int32_t onCredits()
6094 {
6095 return D_O_K;
6096 }
6097
6098 const char *midilist(int32_t index, int32_t *list_size)
6099 {
6100 if(index<0)
6101 {
6102 *list_size=0;
6103
6104 for(int32_t i=0; i<MAXMIDIS; i++)
6105 if(tunes[i].data)
6106 ++(*list_size);
6107
6108 return NULL;
6109 }
6110
6111 int32_t i=0,m=0;
6112
6113 while(m<=index && i<=MAXMIDIS)
6114 {
6115 if(tunes[i].data)
6116 ++m;
6117
6118 ++i;
6119 }
6120
6121 --i;
6122
6123 if(i==MAXMIDIS && m<index)
6124 return "(null)";
6125
6126 return tunes[i].title;
6127 }
6128
6129 /* ------- MIDI info stuff -------- */
6130
6131 char *text;
6132 midi_info *zmi;
6133 bool dialog_running;
6134 bool listening;
6135
6136 void get_info(int32_t index);
6137
6138 int32_t d_midilist_proc(int32_t msg,DIALOG *d,int32_t c)
6139 {
6140 int32_t d2 = d->d2;
6141 int32_t ret = jwin_droplist_proc(msg,d,c);
6142
6143 if(d2!=d->d2)
6144 {
6145 get_info(d->d2);
6146 }
6147
6148 return ret;
6149 }
6150
6151 int32_t d_listen_proc(int32_t msg,DIALOG *d,int32_t c)
6152 {
6153 /* 'd->d1' is offset from 'd' in DIALOG array to midilist proc */
6154
6155 int32_t ret = jwin_button_proc(msg,d,c);
6156
6157 if(ret == D_CLOSE)
6158 {
6159 // get current midi index
6160 int32_t index = (d+(d->d1))->d2;
6161 int32_t i=0, m=0;
6162
6163 while(m<=index && i<=MAXMIDIS)
6164 {
6165 if(tunes[i].data)
6166 ++m;
6167
6168 ++i;
6169 }
6170
6171 --i;
6172 jukebox(i);
6173 listening = true;
6174 ret = D_O_K;
6175 }
6176
6177 return ret;
6178 }
6179
6180 int32_t d_savemidi_proc(int32_t msg,DIALOG *d,int32_t c)
6181 {
6182 /* 'd->d1' is offset from 'd' in DIALOG array to midilist proc */
6183
6184 int32_t ret = jwin_button_proc(msg,d,c);
6185
6186 if(ret == D_CLOSE)
6187 {
6188 // get current midi index
6189 int32_t index = (d+(d->d1))->d2;
6190 int32_t i=0, m=0;
6191
6192 while(m<=index && i<=MAXMIDIS)
6193 {
6194 if(tunes[i].data)
6195 ++m;
6196
6197 ++i;
6198 }
6199
6200 --i;
6201
6202 char title[40] = "Save MIDI: ";
6203 static EXT_LIST list[] =
6204 {
6205 { (char *)"MIDI files (*.mid)", (char *)"mid" },
6206 { NULL, NULL }
6207 };
6208
6209 strcpy(title+11, tunes[i].title);
6210 title[39] = '\0';
6211
6212 std::string fname;
6213 if (auto result = prompt_for_new_file(title, "", list, "tune.mid"))
6214 fname = *result;
6215 else
6216 goto done;
6217
6218 if(exists(fname.c_str()))
6219 {
6220 if(jwin_alert(title, fname.c_str(), "already exists.", "Overwrite it?", "&Yes","&No",'y','n',get_zc_font(font_lfont))==2)
6221 goto done;
6222 }
6223
6224 // save midi i
6225
6226 if (save_midi(fname.c_str(), tunes[i].data) != 0)
6227 jwin_alert(title, "Error saving MIDI to", fname.c_str(), NULL, "Darn", NULL,13,27,get_zc_font(font_lfont));
6228
6229 done:
6230 chop_path(fname.data());
6231 ret = D_REDRAW;
6232 }
6233
6234 return ret;
6235 }
6236
6237 403 static ListData midi_list(midilist, &font);
6238
6239 static DIALOG midi_dlg[] =
6240 {
6241 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */
6242 { jwin_win_proc, 8, 28, 304, 184, 0, 0, 0, D_EXIT, 0, 0, (void *) "MIDI Info", NULL, NULL },
6243 { jwin_text_proc, 32, 60, 40, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Tune:", NULL, NULL },
6244 { d_midilist_proc, 80, 56, 192, 16, 0, 0, 0, 0, 0, 0, (void *) &midi_list, NULL, NULL },
6245 { jwin_textbox_proc, 15, 80, 290, 96, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
6246 { d_listen_proc, 24, 183, 72, 21, 0, 0, 'l', D_EXIT, -2, 0, (void *) "&Listen", NULL, NULL },
6247 { d_savemidi_proc, 108, 183, 72, 21, 0, 0, 's', D_EXIT, -3, 0, (void *) "&Save", NULL, NULL },
6248 { jwin_button_proc, 236, 183, 61, 21, 0, 0, 'k', D_EXIT, 0, 0, (void *) "O&K", NULL, NULL },
6249 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
6250 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
6251 };
6252
6253 void get_info(int32_t index)
6254 {
6255 int32_t i=0, m=0;
6256
6257 while(m<=index && i<=MAXMIDIS)
6258 {
6259 if(tunes[i].data)
6260 ++m;
6261
6262 ++i;
6263 }
6264
6265 --i;
6266
6267 if(i==MAXMIDIS && m<index)
6268 strcpy(text,"(null)");
6269 else
6270 {
6271 get_midi_info(tunes[i].data,zmi);
6272 get_midi_text(tunes[i].data,zmi,text);
6273 }
6274
6275 midi_dlg[0].dp2=get_zc_font(font_lfont);
6276 midi_dlg[3].dp = text;
6277 midi_dlg[3].d1 = midi_dlg[3].d2 = 0;
6278 midi_dlg[5].flags = (tunes[i].flags&tfDISABLESAVE) ? D_DISABLED : D_EXIT;
6279
6280 if(dialog_running)
6281 {
6282 jwin_textbox_proc(MSG_DRAW,midi_dlg+3,0);
6283 d_savemidi_proc(MSG_DRAW,midi_dlg+5,0);
6284 }
6285 }
6286
6287 int32_t onMIDICredits()
6288 {
6289 text = (char*)malloc(4096);
6290 zmi = (midi_info*)malloc(sizeof(midi_info));
6291
6292 if(!text || !zmi)
6293 {
6294 jwin_alert(NULL,"Not enough memory",NULL,NULL,"OK",NULL,13,27,get_zc_font(font_lfont));
6295 return D_O_K;
6296 }
6297
6298 bool do_pause_midi = midi_pos >= 0 && currmidi;
6299 auto restore_midi = currmidi;
6300 if(do_pause_midi)
6301 {
6302 paused_midi_pos = midi_pos;
6303 stop_midi();
6304 midi_suspended = midissuspHALTED;
6305 }
6306
6307 midi_dlg[0].dp2=get_zc_font(font_lfont);
6308 midi_dlg[2].d1 = 0;
6309 midi_dlg[2].d2 = 0;
6310 midi_dlg[4].flags = D_EXIT;
6311 midi_dlg[5].flags = (tunes[midi_dlg[2].d1].flags&tfDISABLESAVE) ? D_DISABLED : D_EXIT;
6312
6313 listening = false;
6314 dialog_running=false;
6315 get_info(0);
6316
6317 dialog_running=true;
6318
6319 large_dialog(midi_dlg);
6320
6321 do_zqdialog(midi_dlg,0);
6322 dialog_running=false;
6323
6324 if(listening)
6325 music_stop();
6326
6327 if(do_pause_midi)
6328 {
6329 // TODO: this probably doesn't resume midis nicely when scrolling (or in some other inner-gameloop).
6330 midi_suspended = midissuspRESUME;
6331 currmidi = restore_midi;
6332 midi_pos = paused_midi_pos;
6333 }
6334
6335 if(text) free(text);
6336 if(zmi) free(zmi);
6337 return D_O_K;
6338 }
6339
6340 int32_t onAbout()
6341 {
6342 char buf1[80]={0};
6343 std::ostringstream oss;
6344 sprintf(buf1,"ZQuest Classic Player");
6345 oss << buf1 << '\n';
6346 sprintf(buf1,"Version: %s", getVersionString());
6347 oss << buf1 << '\n';
6348 sprintf(buf1,"Build Date: %s %s, %d at @ %s %s", dayextension(BUILDTM_DAY).c_str(), (char*)months[BUILDTM_MONTH], BUILDTM_YEAR, __TIME__, __TIMEZONE__);
6349 oss << buf1 << '\n';
6350
6351 InfoDialog("About ZC", oss.str()).show();
6352 return D_O_K;
6353 }
6354
6355 int32_t onQuest()
6356 {
6357 char fname[100];
6358 strcpy(fname, get_filename(qstpath));
6359 quest_dlg[0].dp2=get_zc_font(font_lfont);
6360 quest_dlg[1].dp = fname;
6361
6362 if(QHeader.quest_number==0)
6363 sprintf(str_a,"Custom");
6364 else
6365 sprintf(str_a,"%d",QHeader.quest_number);
6366
6367 sprintf(str_s,"%s",QHeader.getVerStr());
6368
6369 quest_dlg[11].d1 = quest_dlg[9].d1 = 0;
6370 quest_dlg[11].d2 = quest_dlg[9].d2 = 0;
6371
6372 large_dialog(quest_dlg);
6373
6374 do_zqdialog(quest_dlg, 0);
6375 return D_O_K;
6376 }
6377
6378 void call_vidmode_dlg();
6379 int32_t onVidMode()
6380 {
6381 call_vidmode_dlg();
6382 return D_O_K;
6383 }
6384
6385 #define addToHash(c,b,h) if(h->find(c ## key) == h->end()) \
6386 {(*h)[c ## key]=true;} else { if ( c ## key != 0 ) b = false;}
6387 //Added an extra statement, so that if the key is cleared to 0, the cleared
6388 //keybinding status need not be unique. -Z ( 1st April, 2019 )
6389
6390 void load_ukeys(int32_t* arr)
6391 {
6392 arr[ukey_a] = Akey;
6393 arr[ukey_b] = Bkey;
6394 arr[ukey_s] = Skey;
6395 arr[ukey_l] = Lkey;
6396 arr[ukey_r] = Rkey;
6397 arr[ukey_p] = Pkey;
6398 arr[ukey_ex1] = Exkey1;
6399 arr[ukey_ex2] = Exkey2;
6400 arr[ukey_ex3] = Exkey3;
6401 arr[ukey_ex4] = Exkey4;
6402 arr[ukey_du] = DUkey;
6403 arr[ukey_dd] = DDkey;
6404 arr[ukey_dl] = DLkey;
6405 arr[ukey_dr] = DRkey;
6406 arr[ukey_mod1a] = cheat_modifier_keys[0];
6407 arr[ukey_mod1b] = cheat_modifier_keys[1];
6408 arr[ukey_mod2a] = cheat_modifier_keys[2];
6409 arr[ukey_mod2b] = cheat_modifier_keys[3];
6410 };
6411
6412 static const char* ukey_names[] = {
6413 "A", "B", "Start", "L", "R", "Map",
6414 "Ex1", "Ex2", "Ex3", "Ex4", "Up", "Down",
6415 "Left", "Right", "Cheat Mod L1", "Cheat Mod L2",
6416 "Cheat Mod R1", "Cheat Mod R2",
6417 };
6418 std::string get_ukey_name(int32_t k)
6419 {
6420 if (k < num_ukey) return ukey_names[k];
6421 return "";
6422 }
6423
6424 int32_t onKeyboard()
6425 {
6426 int32_t a = Akey;
6427 int32_t b = Bkey;
6428 int32_t s = Skey;
6429 int32_t l = Lkey;
6430 int32_t r = Rkey;
6431 int32_t p = Pkey;
6432 int32_t ex1 = Exkey1;
6433 int32_t ex2 = Exkey2;
6434 int32_t ex3 = Exkey3;
6435 int32_t ex4 = Exkey4;
6436 int32_t du = DUkey;
6437 int32_t dd = DDkey;
6438 int32_t dl = DLkey;
6439 int32_t dr = DRkey;
6440 int32_t mod1a = cheat_modifier_keys[0];
6441 int32_t mod1b = cheat_modifier_keys[1];
6442 int32_t mod2a = cheat_modifier_keys[2];
6443 int32_t mod2b = cheat_modifier_keys[3];
6444 bool done=false;
6445 int32_t ret;
6446
6447 keyboard_control_dlg[0].dp2=get_zc_font(font_lfont);
6448
6449 large_dialog(keyboard_control_dlg);
6450
6451 while(!done)
6452 {
6453 ret = do_zqdialog(keyboard_control_dlg,3);
6454
6455 if(ret==3) // OK
6456 {
6457 int32_t ukeys[num_ukey];
6458 load_ukeys(ukeys);
6459 std::vector<std::string> uniqueError;
6460 for(int32_t q = 0; q < num_ukey; ++q)
6461 {
6462 for(int32_t p = q+1; p < num_ukey; ++p)
6463 {
6464 if(ukeys[q] == ukeys[p] && ukeys[q] != 0)
6465 {
6466 char buf[64];
6467 sprintf(buf, "'%s' conflicts with '%s'", get_ukey_name(q).c_str(), get_ukey_name(p).c_str());
6468 std::string str(buf);
6469 uniqueError.push_back(str);
6470 }
6471 }
6472 }
6473 if(uniqueError.size() == 0)
6474 {
6475 done = true;
6476 save_control_configs(true);
6477 }
6478 else
6479 {
6480 box_start(1, "Duplicate Keys", get_zc_font(font_lfont), get_zc_font(font_sfont), false, keyboard_control_dlg[0].w,keyboard_control_dlg[0].h, 2);
6481 box_out("Cannot have duplicate keybinds!"); box_eol();
6482 for(std::vector<std::string>::iterator it = uniqueError.begin();
6483 it != uniqueError.end(); ++it)
6484 {
6485 box_out((*it).c_str()); box_eol();
6486 }
6487 box_end(true);
6488 }
6489 }
6490 else // Cancel
6491 {
6492 Akey = a;
6493 Bkey = b;
6494 Skey = s;
6495 Lkey = l;
6496 Rkey = r;
6497 Pkey = p;
6498 Exkey1 = ex1;
6499 Exkey2 = ex2;
6500 Exkey3 = ex3;
6501 Exkey4 = ex4;
6502 DUkey = du;
6503 DDkey = dd;
6504 DLkey = dl;
6505 DRkey = dr;
6506 cheat_modifier_keys[0] = mod1a;
6507 cheat_modifier_keys[1] = mod1b;
6508 cheat_modifier_keys[2] = mod2a;
6509 cheat_modifier_keys[3] = mod2b;
6510
6511 done=true;
6512 }
6513
6514 rest(1);
6515 }
6516
6517 return D_O_K;
6518 }
6519
6520 int32_t onGamepad()
6521 {
6522 if (al_get_num_joysticks() == 0)
6523 {
6524 InfoDialog("ZC", "No gamepads detected.").show();
6525 return D_O_K;
6526 }
6527
6528 int32_t a = Abtn;
6529 int32_t b = Bbtn;
6530 int32_t s = Sbtn;
6531 int32_t l = Lbtn;
6532 int32_t r = Rbtn;
6533 int32_t m = Mbtn;
6534 int32_t p = Pbtn;
6535 int32_t ex1 = Exbtn1;
6536 int32_t ex2 = Exbtn2;
6537 int32_t ex3 = Exbtn3;
6538 int32_t ex4 = Exbtn4;
6539 int32_t up = DUbtn;
6540 int32_t down = DDbtn;
6541 int32_t left = DLbtn;
6542 int32_t right = DRbtn;
6543 int32_t joy = joystick_index;
6544 int32_t stick_1 = js_stick_1_x_stick;
6545 int32_t stick_2 = js_stick_2_x_stick;
6546
6547 gamepad_dlg[0].dp2=get_zc_font(font_lfont);
6548 if(analog_movement)
6549 gamepad_dlg[56].flags|=D_SELECTED;
6550 else
6551 gamepad_dlg[56].flags&=~D_SELECTED;
6552
6553 // TODO: should use controller device GUID or name instead of index, otherwise this value is not
6554 // consistent unless exact same number of joysticks is always connected. Name is problematic b/c
6555 // xinput driver doesn't actually get a name (at least, doesn't for my Xbox controller).
6556 // TODO: should store gamepad control mappings per-controller, otherwise switching joystick
6557 // requires remapping every time.
6558 if (joystick_index >= al_get_num_joysticks())
6559 joystick_index = 0;
6560 gamepad_dlg[61].d2 = joystick_index;
6561
6562 gamepad_dlg_cur_joystick = al_get_joystick(joystick_index);
6563 if (!gamepad_dlg_cur_joystick)
6564 {
6565 InfoDialog("ZC", "Invalid gamepad. Did it disconnect?").show();
6566 return D_CLOSE;
6567 }
6568
6569 large_dialog(gamepad_dlg);
6570
6571 int32_t ret = do_zqdialog(gamepad_dlg,4);
6572
6573 if(ret == 4) //OK
6574 {
6575 analog_movement = gamepad_dlg[56].flags&D_SELECTED;
6576 joystick_index = gamepad_dlg[61].d2;
6577 gamepad_dlg_cur_joystick = al_get_joystick(joystick_index);
6578 if (!gamepad_dlg_cur_joystick)
6579 {
6580 InfoDialog("ZC", "Invalid gamepad. Did it disconnect?").show();
6581 return D_CLOSE;
6582 }
6583 js_stick_1_y_stick = js_stick_1_x_stick;
6584 js_stick_2_y_stick = js_stick_2_x_stick;
6585 save_control_configs(false);
6586 }
6587 else //Cancel
6588 {
6589 Abtn = a;
6590 Bbtn = b;
6591 Sbtn = s;
6592 Lbtn = l;
6593 Rbtn = r;
6594 Mbtn = m;
6595 Pbtn = p;
6596 Exbtn1 = ex1;
6597 Exbtn2 = ex2;
6598 Exbtn3 = ex3;
6599 Exbtn4 = ex4;
6600 DUbtn = up;
6601 DDbtn = down;
6602 DLbtn = left;
6603 DRbtn = right;
6604 joystick_index = joy;
6605 js_stick_1_x_stick = stick_1;
6606 js_stick_2_x_stick = stick_2;
6607 }
6608
6609 return D_O_K;
6610 }
6611
6612 int32_t onCheatKeys()
6613 {
6614 int32_t oldcheats[Cheat::Last][2];
6615 memcpy(oldcheats, cheatkeys, sizeof(cheatkeys));
6616
6617 bool done=false;
6618
6619 while(!done)
6620 {
6621 bool confirm = false;
6622 CheatKeysDialog(&confirm).show();
6623 if(confirm) // OK
6624 {
6625 std::vector<std::string> uniqueError;
6626 char buf[512];
6627 for(size_t q = 1; q < Cheat::Last; ++q)
6628 {
6629 if(cheatkeys[q][1] && !cheatkeys[q][0])
6630 {
6631 cheatkeys[q][0] = cheatkeys[q][1];
6632 cheatkeys[q][1] = 0;
6633 }
6634 }
6635 for(size_t q = 1; q < Cheat::Last; ++q)
6636 {
6637 if(!bindable_cheat((Cheat)q)) continue;
6638 for(size_t p = q+1; p < Cheat::Last; ++p)
6639 {
6640 if(!bindable_cheat((Cheat)p)) continue;
6641 for(size_t q2 = 0; q2 <= 1; ++q2)
6642 for(size_t p2 = 0; p2 <= 1; ++p2)
6643 {
6644 if(cheatkeys[q][q2] == cheatkeys[p][p2] && cheatkeys[q][q2] != 0)
6645 {
6646 uniqueError.push_back(fmt::format("'{}' ({}) conflicts with '{}' ({}) - both '{}'",
6647 cheat_to_string((Cheat)q), q2?"Alt":"Main",
6648 cheat_to_string((Cheat)p), p2?"Alt":"Main",
6649 get_keystr(cheatkeys[q][q2])));
6650 }
6651 }
6652 }
6653 }
6654 if(uniqueError.size() == 0)
6655 {
6656 done = true;
6657 save_cheatkeys();
6658 }
6659 else
6660 {
6661 box_start(1, "Duplicate Keys", get_zc_font(font_lfont), get_zc_font(font_sfont), false, 500,400, 2);
6662 box_out("Cannot have duplicate keybinds!"); box_eol();
6663 for(std::vector<std::string>::iterator it = uniqueError.begin();
6664 it != uniqueError.end(); ++it)
6665 {
6666 box_out((*it).c_str()); box_eol();
6667 }
6668 box_end(true);
6669 }
6670 }
6671 else // Cancel
6672 {
6673 memcpy(cheatkeys, oldcheats, sizeof(cheatkeys));
6674 done=true;
6675 }
6676 rest(1);
6677 }
6678
6679 return D_O_K;
6680 }
6681
6682 int32_t onSound()
6683 {
6684 if (get_qr(qr_OLD_SCRIPT_VOLUME))
6685 {
6686 if (FFCore.coreflags & FFCORE_SCRIPTED_MIDI_VOLUME)
6687 {
6688 master_volume(-1, ((int32_t)FFCore.usr_midi_volume));
6689 }
6690 if (FFCore.coreflags & FFCORE_SCRIPTED_DIGI_VOLUME)
6691 {
6692 master_volume((int32_t)(FFCore.usr_digi_volume), 1);
6693 }
6694 if (FFCore.coreflags & FFCORE_SCRIPTED_MUSIC_VOLUME)
6695 {
6696 emusic_volume = (int32_t)FFCore.usr_music_volume;
6697 }
6698 if (FFCore.coreflags & FFCORE_SCRIPTED_SFX_VOLUME)
6699 {
6700 sfx_volume = (int32_t)FFCore.usr_sfx_volume;
6701 }
6702 }
6703 if ( FFCore.coreflags&FFCORE_SCRIPTED_PANSTYLE )
6704 {
6705 pan_style = (int32_t)FFCore.usr_panstyle;
6706 }
6707
6708 int32_t m = midi_volume;
6709 int32_t e = emusic_volume;
6710 int32_t s = sfx_volume;
6711 int32_t p = pan_style;
6712 pan_style = vbound(pan_style,0,3);
6713
6714 sound_dlg[0].dp2=get_zc_font(font_lfont);
6715
6716 large_dialog(sound_dlg);
6717
6718 midi_dp[1] = sound_dlg[6].x;
6719 midi_dp[2] = sound_dlg[6].y;
6720 emus_dp[1] = sound_dlg[8].x;
6721 emus_dp[2] = sound_dlg[8].y;
6722 sfx_dp[1] = sound_dlg[10].x;
6723 sfx_dp[2] = sound_dlg[10].y;
6724 pan_dp[1] = sound_dlg[11].x;
6725 pan_dp[2] = sound_dlg[11].y;
6726 sound_dlg[15].d2 = (midi_volume==255) ? 32 : midi_volume>>3;
6727 sound_dlg[17].d2 = (emusic_volume==255) ? 32 : emusic_volume>>3;
6728 sound_dlg[19].d2 = (sfx_volume==255) ? 32 : sfx_volume>>3;
6729 sound_dlg[20].d2 = pan_style;
6730
6731 int32_t ret = do_zqdialog(sound_dlg,1);
6732
6733 if(ret==2)
6734 {
6735 master_volume(digi_volume,midi_volume);
6736 if (zcmusic)
6737 zcmusic_set_volume(zcmusic, emusic_volume);
6738
6739 int32_t temp_volume = sfx_volume;
6740 if (GameLoaded && !get_qr(qr_OLD_SCRIPT_VOLUME))
6741 temp_volume = (sfx_volume * FFCore.usr_sfx_volume) / 10000 / 100;
6742 for(int32_t i=0; i<WAV_COUNT; ++i)
6743 {
6744 if(sfx_voice[i] >= 0)
6745 voice_set_volume(sfx_voice[i], temp_volume);
6746 }
6747 zc_set_config(sfx_sect,"midi",midi_volume);
6748 zc_set_config(sfx_sect,"sfx",sfx_volume);
6749 zc_set_config(sfx_sect,"emusic",emusic_volume);
6750 zc_set_config(sfx_sect,"pan",pan_style);
6751 }
6752 else
6753 {
6754 midi_volume = m;
6755 emusic_volume = e;
6756 sfx_volume = s;
6757 pan_style = p;
6758 }
6759
6760 return D_O_K;
6761 }
6762
6763 int32_t queding(char const* s1, char const* s2, char const* s3)
6764 {
6765 return jwin_alert("ZQuest Classic",s1,s2,s3,"&Yes","&No",'y','n',get_zc_font(font_lfont));
6766 }
6767
6768 int32_t onQuit()
6769 {
6770 if(Playing)
6771 {
6772 int32_t ret=0;
6773
6774 if(get_qr(qr_NOCONTINUE))
6775 {
6776 if(standalone_mode)
6777 {
6778 ret=queding("End current game?",
6779 "The continue screen is disabled; the game",
6780 "will be reloaded from the last save.");
6781 }
6782 else
6783 {
6784 ret=queding("End current game?",
6785 "The continue screen is disabled. You will",
6786 "be returned to the file select screen.");
6787 }
6788 }
6789 else
6790 ret=queding("End current game?",NULL,NULL);
6791
6792 if(ret==1)
6793 {
6794 disableClickToFreeze=false;
6795 Quit=qQUIT;
6796
6797 // Trying to evade a door repair charge?
6798 if(repaircharge)
6799 {
6800 game->change_drupy(-repaircharge);
6801 repaircharge=0;
6802 }
6803
6804 return D_CLOSE;
6805 }
6806 }
6807
6808 return D_O_K;
6809 }
6810
6811 int32_t onTryQuitMenu()
6812 {
6813 return onTryQuit(true);
6814 }
6815
6816 int32_t onTryQuit(bool inMenu)
6817 {
6818 if(Playing && !(GameFlags & GAMEFLAG_NO_F6))
6819 {
6820 if(active_cutscene.can_f6())
6821 {
6822 if(get_qr(qr_OLD_F6))
6823 {
6824 if(inMenu) onQuit();
6825 else /*if(!get_qr(qr_NOCONTINUE))*/ f_Quit(qQUIT);
6826 }
6827 else
6828 {
6829 disableClickToFreeze=false;
6830 GameFlags |= GAMEFLAG_TRYQUIT;
6831 }
6832 return D_CLOSE;
6833 }
6834 else active_cutscene.error();
6835 }
6836
6837 return D_O_K;
6838 }
6839
6840 int32_t onReset()
6841 {
6842 if(queding(" Reset system? ",NULL,NULL)==1)
6843 {
6844 disableClickToFreeze=false;
6845 Quit=qRESET;
6846 replay_quit();
6847 return D_CLOSE;
6848 }
6849
6850 return D_O_K;
6851 }
6852
6853 int32_t onExit()
6854 {
6855 if(queding(" Quit ZQuest Classic? ",NULL,NULL)==1)
6856 {
6857 Quit=qEXIT;
6858 return D_CLOSE;
6859 }
6860
6861 return D_O_K;
6862 }
6863
6864 int32_t onDebug()
6865 {
6866 if(debug_enabled)
6867 set_debug(!get_debug());
6868 return D_O_K;
6869 }
6870
6871 int32_t onHeartBeep()
6872 {
6873 heart_beep=!heart_beep;
6874 zc_set_config(cfg_sect,"heart_beep",heart_beep);
6875 return D_O_K;
6876 }
6877
6878 int32_t onSaveIndicator()
6879 {
6880 use_save_indicator = use_save_indicator ? 0 : 1;
6881 zc_set_config(cfg_sect,"save_indicator",use_save_indicator);
6882 return D_O_K;
6883 }
6884
6885 int32_t onEpilepsy()
6886 {
6887 if(jwin_alert3(
6888 "Epilepsy Flash Reduction",
6889 "Enabling this will reduce the intensity of flashing and screen wave effects.",
6890 "Disabling this will restore standard flash and wavy behaviour.",
6891 "Proceed?",
6892 "&Yes",
6893 "&No",
6894 NULL,
6895 'y',
6896 'n',
6897 0,
6898 get_zc_font(font_lfont)) == 1)
6899 {
6900 epilepsyFlashReduction = epilepsyFlashReduction ? 0 : 1;
6901 zc_set_config(cfg_sect,"epilepsy_flash_reduction",epilepsyFlashReduction);
6902 }
6903 return D_O_K;
6904 }
6905
6906 bool rc = false;
6907
6908 static DIALOG getnum_dlg[] =
6909 {
6910 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
6911 { jwin_win_proc, 80, 80, 160, 72, vc(0), vc(11), 0, D_EXIT, 0, 0, NULL, NULL, NULL },
6912 { jwin_text_proc, 104, 104+4, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Number:", NULL, NULL },
6913 { jwin_edit_proc, 168, 104, 48, 16, 0, 0, 0, 0, 6, 0, NULL, NULL, NULL },
6914 { jwin_button_proc, 90, 126, 61, 21, vc(0), vc(11), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
6915 { jwin_button_proc, 170, 126, 61, 21, vc(0), vc(11), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
6916 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
6917 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
6918 };
6919
6920 int32_t getnumber(const char *prompt,int32_t initialval)
6921 {
6922 char buf[20];
6923 sprintf(buf,"%d",initialval);
6924 getnum_dlg[0].dp=(void *)prompt;
6925 getnum_dlg[0].dp2=get_zc_font(font_lfont);
6926 getnum_dlg[2].dp=buf;
6927
6928 large_dialog(getnum_dlg);
6929
6930 if(do_zqdialog(getnum_dlg,2)==3)
6931 return atoi(buf);
6932
6933 return initialval;
6934 }
6935
6936 int32_t onLife()
6937 {
6938 int value = vbound(getnumber("Life",game->get_life()),1,game->get_maxlife());
6939 cheats_enqueue(Cheat::Life, value);
6940 return D_O_K;
6941 }
6942
6943 int32_t onHeartC()
6944 {
6945 int max_life = vbound(getnumber("Heart Containers",game->get_maxlife()/game->get_hp_per_heart()),1,4095) * game->get_hp_per_heart();
6946 int life = vbound(getnumber("Life",game->get_life()/game->get_hp_per_heart()),1,max_life/game->get_hp_per_heart())*game->get_hp_per_heart();
6947 cheats_enqueue(Cheat::MaxLife, max_life);
6948 cheats_enqueue(Cheat::Life, life);
6949 return D_O_K;
6950 }
6951
6952 int32_t onMagicC()
6953 {
6954 int max_magic = vbound(getnumber("Magic Containers",game->get_maxmagic()/game->get_mp_per_block()),0,2047) * game->get_mp_per_block();
6955 int magic = vbound(getnumber("Magic",game->get_magic()/game->get_mp_per_block()),0,max_magic/game->get_mp_per_block())*game->get_mp_per_block();
6956 cheats_enqueue(Cheat::MaxMagic, max_magic);
6957 cheats_enqueue(Cheat::Magic, magic);
6958 return D_O_K;
6959 }
6960
6961 int32_t onRupies()
6962 {
6963 int value = vbound(getnumber("Rupees",game->get_rupies()),0,game->get_maxcounter(1));
6964 cheats_enqueue(Cheat::Rupies, value);
6965 return D_O_K;
6966 }
6967
6968 int32_t onMaxBombs()
6969 {
6970 int value = vbound(getnumber("Max Bombs",game->get_maxbombs()),0,0xFFFF);
6971 cheats_enqueue(Cheat::MaxBombs, value);
6972 cheats_enqueue(Cheat::Bombs, value);
6973 return D_O_K;
6974 }
6975
6976 int32_t onRefillLife()
6977 {
6978 cheats_enqueue(Cheat::Life, game->get_maxlife());
6979 return D_O_K;
6980 }
6981 int32_t onRefillMagic()
6982 {
6983 cheats_enqueue(Cheat::Magic, game->get_maxmagic());
6984 return D_O_K;
6985 }
6986 int32_t onClock()
6987 {
6988 cheats_enqueue(Cheat::Clock);
6989 return D_O_K;
6990 }
6991
6992 int32_t onQstPath()
6993 {
6994 char initial_path[2048];
6995 chop_path(qstdir);
6996 strcpy(initial_path, qstdir);
6997
6998 if (auto result = prompt_for_existing_folder("Quest File Directory", initial_path, "qst"))
6999 {
7000 char* path = result->data();
7001 chop_path(path);
7002 fix_filename_case(path);
7003 fix_filename_slashes(path);
7004 strcpy(qstdir,path);
7005 strcpy(qstpath,qstdir);
7006 zc_set_config("zeldadx","quest_dir",qstdir);
7007 flush_config_file();
7008 }
7009
7010 return D_O_K;
7011 }
7012
7013 #include "dialog/cheat_dialog.h"
7014 int32_t onCheat()
7015 {
7016 call_setcheat_dialog();
7017 game->set_cheat(maxcheat);
7018 if(cheat) game->did_cheat(true);
7019 return D_O_K;
7020 }
7021
7022 int32_t onCheatRupies()
7023 {
7024 cheats_enqueue(Cheat::Rupies, game->get_maxcounter(1));
7025 return D_O_K;
7026 }
7027
7028 int32_t onCheatArrows()
7029 {
7030 cheats_enqueue(Cheat::Arrows, game->get_maxarrows());
7031 return D_O_K;
7032 }
7033
7034 int32_t onCheatBombs()
7035 {
7036 cheats_enqueue(Cheat::Bombs, game->get_maxbombs(), game->get_maxcounter(6));
7037 return D_O_K;
7038 }
7039
7040 // *** screen saver
7041
7042 18339918 int32_t after_time()
7043 {
7044
1/2
✓ Branch 0 taken 18339918 times.
✗ Branch 1 not taken.
18339918 if(ss_enable == 0)
7045 return INT_MAX;
7046
7047
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18339918 times.
18339918 if(ss_after <= 0)
7048 return 5 * 60;
7049
7050
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18339918 times.
18339918 if(ss_after <= 3)
7051 return ss_after * 15 * 60;
7052
7053
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18339918 times.
18339918 if(ss_after <= 13)
7054 return (ss_after - 3) * 60 * 60;
7055
7056 18339918 return MAX_IDLE + 1;
7057 18339918 }
7058
7059 static const char *after_str[15] =
7060 {
7061 " 5 sec", "15 sec", "30 sec", "45 sec", " 1 min", " 2 min", " 3 min",
7062 " 4 min", " 5 min", " 6 min", " 7 min", " 8 min", " 9 min", "10 min",
7063 "Never"
7064 };
7065
7066 const char *after_list(int32_t index, int32_t *list_size)
7067 {
7068 if(index < 0)
7069 {
7070 *list_size = 15;
7071 return NULL;
7072 }
7073
7074 return after_str[index];
7075 }
7076
7077 403 static ListData after__list(after_list, &font);
7078
7079 static DIALOG scrsaver_dlg[] =
7080 {
7081 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */
7082 403 { jwin_win_proc, 32, 64, 256, 136, 0, 0, 0, D_EXIT, 0, 0, (void *) "Screen Saver Settings", NULL, NULL },
7083 403 { jwin_frame_proc, 42, 92, 236, 70, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
7084 403 { jwin_text_proc, 60, 104, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Run After", NULL, NULL },
7085 403 { jwin_text_proc, 60, 128, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Speed", NULL, NULL },
7086 403 { jwin_text_proc, 60, 144, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Density", NULL, NULL },
7087 403 { jwin_droplist_proc, 144, 100, 96, 16, 0, 0, 0, 0, 0, 0, (void *) &after__list, NULL, NULL },
7088 403 { jwin_slider_proc, 144, 128, 116, 8, vc(0), jwin_pal[jcBOX], 0, 0, 6, 0, NULL, NULL, NULL },
7089 403 { jwin_slider_proc, 144, 144, 116, 8, vc(0), jwin_pal[jcBOX], 0, 0, 6, 0, NULL, NULL, NULL },
7090 403 { jwin_button_proc, 42, 170, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
7091 403 { jwin_button_proc, 124, 170, 72, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "Preview", NULL, NULL },
7092 403 { jwin_button_proc, 218, 170, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
7093 403 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
7094 403 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
7095 };
7096
7097 int32_t onScreenSaver()
7098 {
7099 scrsaver_dlg[0].dp2=get_zc_font(font_lfont);
7100 int32_t oldcfgs[3];
7101 scrsaver_dlg[5].d1 = scrsaver_dlg[5].d2 = oldcfgs[0] = ss_after;
7102 scrsaver_dlg[6].d2 = oldcfgs[1] = ss_speed;
7103 scrsaver_dlg[7].d2 = oldcfgs[2] = ss_density;
7104
7105 large_dialog(scrsaver_dlg);
7106
7107 int32_t ret = do_zqdialog(scrsaver_dlg,-1);
7108
7109 if(ret == 8 || ret == 9)
7110 {
7111 ss_after = scrsaver_dlg[5].d1;
7112 ss_speed = scrsaver_dlg[6].d2;
7113 ss_density = scrsaver_dlg[7].d2;
7114 if(oldcfgs[0] != ss_after)
7115 zc_set_config(cfg_sect,"ss_after",ss_after);
7116 if(oldcfgs[1] != ss_speed)
7117 zc_set_config(cfg_sect,"ss_speed",ss_speed);
7118 if(oldcfgs[2] != ss_density)
7119 zc_set_config(cfg_sect,"ss_density",ss_density);
7120 }
7121
7122 if(ret == 9)
7123 // preview Screen Saver
7124 {
7125 clear_keybuf();
7126 Matrix(ss_speed, ss_density, 30);
7127 system_pal(true);
7128 sys_mouse();
7129 }
7130
7131 return D_O_K;
7132 }
7133
7134 /***** Menus *****/
7135
7136 enum
7137 {
7138 MENUID_GAME_LOADQUEST,
7139 MENUID_GAME_ENDGAME,
7140 };
7141
1/4
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
403 static NewMenu game_menu
7142 3224 {
7143
3/6
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 403 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 403 times.
✗ Branch 5 not taken.
403 { "&Continue","ESC", onContinue },
7144
2/4
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 403 times.
✗ Branch 3 not taken.
403 {},
7145
2/4
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 403 times.
✗ Branch 3 not taken.
403 { "L&oad Quest...", onCustomGame, MENUID_GAME_LOADQUEST },
7146
3/6
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 403 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 403 times.
✗ Branch 5 not taken.
403 { "&End Game","F6", onTryQuitMenu, MENUID_GAME_ENDGAME },
7147
2/4
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 403 times.
✗ Branch 3 not taken.
403 {},
7148 #ifdef __EMSCRIPTEN__
7149 { "&Reset","F7", onReset },
7150 #elif defined(ALLEGRO_MACOSX)
7151 { "&Reset","F7", onReset },
7152 { "&Quit","F8", onExit },
7153 #else
7154
3/6
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 403 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 403 times.
✗ Branch 5 not taken.
403 { "&Reset","F9", onReset },
7155
3/6
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 403 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 403 times.
✗ Branch 5 not taken.
403 { "&Quit","F10", onExit },
7156 #endif
7157 };
7158
7159
1/4
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
403 static NewMenu snapshot_format_menu
7160 2821 {
7161
4/8
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 403 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 403 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 403 times.
✗ Branch 7 not taken.
403 { "&BMP", std::bind(onSetSnapshotFormat, ssfmtBMP) },
7162
4/8
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 403 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 403 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 403 times.
✗ Branch 7 not taken.
403 { "&GIF", std::bind(onSetSnapshotFormat, ssfmtGIF) },
7163
4/8
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 403 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 403 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 403 times.
✗ Branch 7 not taken.
403 { "&JPG", std::bind(onSetSnapshotFormat, ssfmtJPG) },
7164
4/8
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 403 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 403 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 403 times.
✗ Branch 7 not taken.
403 { "&PNG", std::bind(onSetSnapshotFormat, ssfmtPNG) },
7165
4/8
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 403 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 403 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 403 times.
✗ Branch 7 not taken.
403 { "PC&X", std::bind(onSetSnapshotFormat, ssfmtPCX) },
7166
4/8
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 403 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 403 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 403 times.
✗ Branch 7 not taken.
403 { "&TGA", std::bind(onSetSnapshotFormat, ssfmtTGA) },
7167 };
7168
7169
1/4
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
403 static NewMenu bottom_8_pixels_menu
7170 1612 {
7171
4/8
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 403 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 403 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 403 times.
✗ Branch 7 not taken.
403 { "&Default (qst)", std::bind(onSetBottom8Pixels, 0) },
7172
4/8
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 403 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 403 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 403 times.
✗ Branch 7 not taken.
403 { "&On", std::bind(onSetBottom8Pixels, 1) },
7173
4/8
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 403 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 403 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 403 times.
✗ Branch 7 not taken.
403 { "&Off", std::bind(onSetBottom8Pixels, 2) },
7174 };
7175
7176
1/4
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
403 static NewMenu controls_menu
7177 1612 {
7178
2/4
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 403 times.
✗ Branch 3 not taken.
403 { "Key&board...", onKeyboard },
7179
2/4
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 403 times.
✗ Branch 3 not taken.
403 { "&Gamepad...", onGamepad },
7180
2/4
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 403 times.
✗ Branch 3 not taken.
403 { "&Cheat Keys...", onCheatKeys },
7181 };
7182
7183
1/4
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
403 static NewMenu name_entry_mode_menu
7184 1612 {
7185
2/4
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 403 times.
✗ Branch 3 not taken.
403 { "&Keyboard", onKeyboardEntry },
7186
2/4
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 403 times.
✗ Branch 3 not taken.
403 { "&Letter Grid", onLetterGridEntry },
7187
2/4
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 403 times.
✗ Branch 3 not taken.
403 { "&Extended Letter Grid", onExtLetterGridEntry },
7188 };
7189
7190 static void set_controls_menu_active()
7191 {
7192
7193 }
7194
7195 enum
7196 {
7197 MENUID_WINDOW_LOCK_ASPECT,
7198 MENUID_WINDOW_LOCK_INTSCALE,
7199 MENUID_WINDOW_SAVE_SIZE,
7200 MENUID_WINDOW_SAVE_POS,
7201 MENUID_WINDOW_STRETCH,
7202 };
7203
1/4
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
403 static NewMenu window_menu
7204 2418 {
7205
2/4
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 403 times.
✗ Branch 3 not taken.
403 { "Lock Aspect Ratio", onDragAspect, MENUID_WINDOW_LOCK_ASPECT },
7206
2/4
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 403 times.
✗ Branch 3 not taken.
403 { "Lock Integer Scale", onIntegerScaling, MENUID_WINDOW_LOCK_INTSCALE },
7207
2/4
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 403 times.
✗ Branch 3 not taken.
403 { "Save Size Changes", onSaveDragResize, MENUID_WINDOW_SAVE_SIZE },
7208
2/4
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 403 times.
✗ Branch 3 not taken.
403 { "Save Position Changes", onWinPosSave, MENUID_WINDOW_SAVE_POS },
7209
2/4
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 403 times.
✗ Branch 3 not taken.
403 { "Stretch Game Area", onStretchGame, MENUID_WINDOW_STRETCH },
7210 };
7211 void call_zc_options_dlg();
7212 enum
7213 {
7214 MENUID_OPTIONS_PAUSE_BG,
7215 MENUID_OPTIONS_EPILEPSYPROT,
7216 MENUID_OPTIONS_SHOWBOTTOMPIXELS,
7217 };
7218
1/4
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
403 static NewMenu options_menu
7219 3224 {
7220
2/4
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 403 times.
✗ Branch 3 not taken.
403 { "Name &Entry Mode", &name_entry_mode_menu },
7221
2/4
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 403 times.
✗ Branch 3 not taken.
403 { "S&napshot Format", &snapshot_format_menu },
7222
2/4
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 403 times.
✗ Branch 3 not taken.
403 { "&Window Settings", &window_menu },
7223
2/4
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 403 times.
✗ Branch 3 not taken.
403 { "Epilepsy Flash Reduction", onEpilepsy, MENUID_OPTIONS_EPILEPSYPROT },
7224
2/4
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 403 times.
✗ Branch 3 not taken.
403 { "Pause In Background", onPauseInBackground, MENUID_OPTIONS_PAUSE_BG },
7225
2/4
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 403 times.
✗ Branch 3 not taken.
403 { "Show Bottom 8 Pixels", &bottom_8_pixels_menu, MENUID_OPTIONS_SHOWBOTTOMPIXELS },
7226
2/4
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 403 times.
✗ Branch 3 not taken.
403 { "More Options", call_zc_options_dlg },
7227 };
7228 enum
7229 {
7230 MENUID_SETTINGS_CONTROLS,
7231 MENUID_SETTINGS_CAPFPS,
7232 MENUID_SETTINGS_SHOWFPS,
7233 MENUID_SETTINGS_SHOWTIME,
7234 MENUID_SETTINGS_CLICK_FREEZE,
7235 MENUID_SETTINGS_TRANSLAYERS,
7236 MENUID_SETTINGS_NESQUIT,
7237 MENUID_SETTINGS_VOLKEYS,
7238 MENUID_SETTINGS_HEARTBEEP,
7239 MENUID_SETTINGS_SAVEINDICATOR,
7240 MENUID_SETTINGS_DEBUG,
7241 };
7242
1/4
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
403 static NewMenu settings_menu
7243 6851 {
7244
2/4
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 403 times.
✗ Branch 3 not taken.
403 { "&Sound...", onSound },
7245
2/4
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 403 times.
✗ Branch 3 not taken.
403 { "C&ontrols", &controls_menu, MENUID_SETTINGS_CONTROLS },
7246
2/4
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 403 times.
✗ Branch 3 not taken.
403 {},
7247
2/4
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 403 times.
✗ Branch 3 not taken.
403 { "Options", &options_menu },
7248
2/4
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 403 times.
✗ Branch 3 not taken.
403 {},
7249
3/6
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 403 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 403 times.
✗ Branch 5 not taken.
403 { "&Cap FPS","F1", onThrottleFPS, MENUID_SETTINGS_CAPFPS },
7250
3/6
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 403 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 403 times.
✗ Branch 5 not taken.
403 { "Show &FPS","F2", onShowFPS, MENUID_SETTINGS_SHOWFPS },
7251
2/4
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 403 times.
✗ Branch 3 not taken.
403 { "Show &Time", onShowTime, MENUID_SETTINGS_SHOWTIME },
7252
2/4
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 403 times.
✗ Branch 3 not taken.
403 { "Click to Freeze", onClickToFreeze, MENUID_SETTINGS_CLICK_FREEZE },
7253
2/4
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 403 times.
✗ Branch 3 not taken.
403 { "Cont. &Heart Beep", onHeartBeep, MENUID_SETTINGS_HEARTBEEP },
7254
2/4
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 403 times.
✗ Branch 3 not taken.
403 { "Show Trans. &Layers", onTransLayers, MENUID_SETTINGS_TRANSLAYERS },
7255
2/4
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 403 times.
✗ Branch 3 not taken.
403 { "Up+A+B To &Quit", onNESquit, MENUID_SETTINGS_NESQUIT },
7256
2/4
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 403 times.
✗ Branch 3 not taken.
403 { "Volume &Keys", onVolKeys, MENUID_SETTINGS_VOLKEYS },
7257
2/4
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 403 times.
✗ Branch 3 not taken.
403 { "Sa&ve Indicator", onSaveIndicator, MENUID_SETTINGS_SAVEINDICATOR },
7258
2/4
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 403 times.
✗ Branch 3 not taken.
403 {},
7259
2/4
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 403 times.
✗ Branch 3 not taken.
403 { "Debu&g", onDebug, MENUID_SETTINGS_DEBUG },
7260 };
7261
7262 enum
7263 {
7264 MENUID_MISC_FULLSCREEN,
7265 MENUID_MISC_VIDMODE,
7266 MENUID_MISC_QUEST_INFO,
7267 MENUID_MISC_QUEST_DIR,
7268 MENUID_MISC_CONSOLE,
7269 MENUID_MISC_CLEAR_CONSOLE_ON_LOAD,
7270 };
7271
1/4
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
403 static NewMenu misc_menu
7272 6045 {
7273
2/4
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 403 times.
✗ Branch 3 not taken.
403 { "&About...", onAbout },
7274 // TODO: re-enable, but: 1) do not use a bitmap thing that is hard to update 2) update names and 3) don't use the Z-word.
7275 // { "&Credits...", onCredits },
7276
2/4
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 403 times.
✗ Branch 3 not taken.
403 { "&Fullscreen", onFullscreenMenu, MENUID_MISC_FULLSCREEN },
7277
2/4
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 403 times.
✗ Branch 3 not taken.
403 { "&Video Mode...", onVidMode, MENUID_MISC_VIDMODE },
7278
2/4
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 403 times.
✗ Branch 3 not taken.
403 {},
7279
2/4
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 403 times.
✗ Branch 3 not taken.
403 { "&Quest Info...", onQuest, MENUID_MISC_QUEST_INFO },
7280
2/4
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 403 times.
✗ Branch 3 not taken.
403 { "Quest &MIDI Info...", onMIDICredits },
7281
2/4
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 403 times.
✗ Branch 3 not taken.
403 { "Quest &Directory...", onQstPath, MENUID_MISC_QUEST_DIR },
7282
2/4
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 403 times.
✗ Branch 3 not taken.
403 {},
7283
2/4
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 403 times.
✗ Branch 3 not taken.
403 { "Take &Snapshot F12", onSnapshot },
7284
2/4
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 403 times.
✗ Branch 3 not taken.
403 { "Sc&reen Saver...", onScreenSaver },
7285
2/4
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 403 times.
✗ Branch 3 not taken.
403 { "Save ZC Configuration", OnSaveZCConfig },
7286
2/4
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 403 times.
✗ Branch 3 not taken.
403 { "Show Console", onConsole, MENUID_MISC_CONSOLE },
7287
2/4
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 403 times.
✗ Branch 3 not taken.
403 { "Clear Console on Qst Load", onClrConsoleOnLoad, MENUID_MISC_CLEAR_CONSOLE_ON_LOAD },
7288
2/4
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 403 times.
✗ Branch 3 not taken.
403 { "Clear Directory Cache", OnnClearQuestDir },
7289 };
7290
7291 enum
7292 {
7293 MENUID_REFILL_ARROWS,
7294 };
7295
1/4
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
403 static NewMenu refill_menu
7296 2418 {
7297
2/4
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 403 times.
✗ Branch 3 not taken.
403 { "&Life", onRefillLife },
7298
2/4
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 403 times.
✗ Branch 3 not taken.
403 { "&Magic", onRefillMagic },
7299
2/4
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 403 times.
✗ Branch 3 not taken.
403 { "&Bombs", onCheatBombs },
7300
2/4
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 403 times.
✗ Branch 3 not taken.
403 { "&Rupees", onCheatRupies },
7301
2/4
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 403 times.
✗ Branch 3 not taken.
403 { "&Arrows", onCheatArrows, MENUID_REFILL_ARROWS },
7302 };
7303
7304 enum
7305 {
7306 MENUID_SHOW_L0,
7307 MENUID_SHOW_L1,
7308 MENUID_SHOW_L2,
7309 MENUID_SHOW_L3,
7310 MENUID_SHOW_L4,
7311 MENUID_SHOW_L5,
7312 MENUID_SHOW_L6,
7313 MENUID_SHOW_OVER,
7314 MENUID_SHOW_PUSH,
7315 MENUID_SHOW_FFC,
7316 MENUID_SHOW_SPR,
7317 MENUID_SHOW_SCRIPTNAME,
7318 MENUID_SHOW_SOLIDITY,
7319 MENUID_SHOW_HITBOX,
7320 MENUID_SHOW_EFFECT,
7321 };
7322
1/4
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
403 static NewMenu show_menu
7323 7657 {
7324
2/4
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 403 times.
✗ Branch 3 not taken.
403 { "Combos", onShowLayer0, MENUID_SHOW_L0 },
7325
2/4
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 403 times.
✗ Branch 3 not taken.
403 { "Layer 1", onShowLayer1, MENUID_SHOW_L1 },
7326
2/4
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 403 times.
✗ Branch 3 not taken.
403 { "Layer 2", onShowLayer2, MENUID_SHOW_L2 },
7327
2/4
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 403 times.
✗ Branch 3 not taken.
403 { "Layer 3", onShowLayer3, MENUID_SHOW_L3 },
7328
2/4
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 403 times.
✗ Branch 3 not taken.
403 { "Layer 4", onShowLayer4, MENUID_SHOW_L4 },
7329
2/4
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 403 times.
✗ Branch 3 not taken.
403 { "Layer 5", onShowLayer5, MENUID_SHOW_L5 },
7330
2/4
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 403 times.
✗ Branch 3 not taken.
403 { "Layer 6", onShowLayer6, MENUID_SHOW_L6 },
7331
2/4
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 403 times.
✗ Branch 3 not taken.
403 { "Overhead Combos", onShowLayerO, MENUID_SHOW_OVER },
7332
2/4
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 403 times.
✗ Branch 3 not taken.
403 { "Push Blocks", onShowLayerP, MENUID_SHOW_PUSH },
7333
2/4
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 403 times.
✗ Branch 3 not taken.
403 { "Freeform Combos", onShowLayerF, MENUID_SHOW_FFC },
7334
2/4
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 403 times.
✗ Branch 3 not taken.
403 { "Sprites", onShowLayerS, MENUID_SHOW_SPR },
7335
2/4
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 403 times.
✗ Branch 3 not taken.
403 {},
7336
2/4
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 403 times.
✗ Branch 3 not taken.
403 { "Current FFC Scripts", onShowFFScripts, MENUID_SHOW_SCRIPTNAME },
7337
2/4
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 403 times.
✗ Branch 3 not taken.
403 {},
7338
2/4
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 403 times.
✗ Branch 3 not taken.
403 { "Walkability", onShowLayerW, MENUID_SHOW_SOLIDITY },
7339
2/4
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 403 times.
✗ Branch 3 not taken.
403 { "Hitboxes", onShowHitboxes, MENUID_SHOW_HITBOX },
7340
2/4
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 403 times.
✗ Branch 3 not taken.
403 { "Effects", onShowLayerE, MENUID_SHOW_EFFECT },
7341
2/4
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 403 times.
✗ Branch 3 not taken.
403 { "Info Opacity", onShowInfoOpacity },
7342 };
7343
7344 enum
7345 {
7346 MENUID_CHEAT_CHOP_L1,
7347 MENUID_CHEAT_CHOP_L2,
7348 MENUID_CHEAT_CHOP_L3,
7349 MENUID_CHEAT_CHOP_L4,
7350 MENUID_CHEAT_INVULN,
7351 MENUID_CHEAT_NOCLIP,
7352 MENUID_CHEAT_IGNORESV,
7353 MENUID_CHEAT_GOFAST,
7354 };
7355
1/4
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
403 static NewMenu cheat_menu
7356 6851 {
7357
2/4
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 403 times.
✗ Branch 3 not taken.
403 { "Set &Cheat", onCheat },
7358
1/2
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
403 { MENUID_CHEAT_CHOP_L1 },
7359
2/4
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 403 times.
✗ Branch 3 not taken.
403 { "Re&fill", &refill_menu },
7360
1/2
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
403 { MENUID_CHEAT_CHOP_L2 },
7361
2/4
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 403 times.
✗ Branch 3 not taken.
403 { "&Invincible", onClock, MENUID_CHEAT_INVULN },
7362
2/4
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 403 times.
✗ Branch 3 not taken.
403 { "Ma&x Bombs...", onMaxBombs },
7363
2/4
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 403 times.
✗ Branch 3 not taken.
403 { "&Heart Containers...", onHeartC },
7364
2/4
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 403 times.
✗ Branch 3 not taken.
403 { "&Magic Containers...", onMagicC },
7365
1/2
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
403 { MENUID_CHEAT_CHOP_L3 },
7366
2/4
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 403 times.
✗ Branch 3 not taken.
403 { "&Hero Data...", onCheatConsole },
7367
1/2
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
403 { MENUID_CHEAT_CHOP_L4 },
7368
2/4
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 403 times.
✗ Branch 3 not taken.
403 { "Walk Through &Walls", onNoWalls, MENUID_CHEAT_NOCLIP },
7369
2/4
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 403 times.
✗ Branch 3 not taken.
403 { "Hero Ignores Side&view", onIgnoreSideview, MENUID_CHEAT_IGNORESV },
7370
2/4
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 403 times.
✗ Branch 3 not taken.
403 { "&Quick Movement", onGoFast, MENUID_CHEAT_GOFAST },
7371
2/4
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 403 times.
✗ Branch 3 not taken.
403 { "&Kill All Enemies", onKillCheat },
7372
2/4
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 403 times.
✗ Branch 3 not taken.
403 { "Trigger &Secrets", onSecretsCheat },
7373
2/4
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 403 times.
✗ Branch 3 not taken.
403 { "Trigger Secrets Perm", onSecretsCheatPerm },
7374
2/4
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 403 times.
✗ Branch 3 not taken.
403 { "Show/Hide Layer", &show_menu },
7375
2/4
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 403 times.
✗ Branch 3 not taken.
403 { "Toggle &Light", onLightSwitch },
7376
2/4
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 403 times.
✗ Branch 3 not taken.
403 { "&Goto Location...", onGoTo },
7377 };
7378
7379 #if DEVLEVEL > 0
7380 int32_t devLogging();
7381 int32_t devDebug();
7382 int32_t devTimestmp();
7383 #if DEVLEVEL > 1
7384 int32_t setCheat();
7385 #endif //DEVLEVEL > 1
7386 enum
7387 {
7388 MENUID_DEV_LOGGING,
7389 MENUID_DEV_DEBUG,
7390 MENUID_DEV_TIMESTAMP,
7391 MENUID_DEV_SETCHEAT,
7392 };
7393 static NewMenu dev_menu
7394 {
7395 { "&Force Error Log", devLogging, MENUID_DEV_LOGGING },
7396 // { "&Extra Debug Log", devDebug, MENUID_DEV_DEBUG },
7397 { "&Timestamp Log", devTimestmp, MENUID_DEV_TIMESTAMP },
7398 #if DEVLEVEL > 1
7399 {},
7400 { "Set &Cheat", setCheat, MENUID_DEV_SETCHEAT },
7401 #endif //DEVLEVEL > 1
7402 };
7403 int32_t devLogging()
7404 {
7405 dev_logging = !dev_logging;
7406 dev_menu.select_uid(MENUID_DEV_LOGGING, dev_logging);
7407 return D_O_K;
7408 }
7409 // int32_t devDebug()
7410 // {
7411 // dev_debug = !dev_debug;
7412 // dev_menu.select_uid(MENUID_DEV_DEBUG, dev_debug);
7413 // dev_menu[dv_dbg].flags = dev_debug ? D_SELECTED : 0;
7414 // return D_O_K;
7415 // }
7416 int32_t devTimestmp()
7417 {
7418 dev_timestmp = !dev_timestmp;
7419 dev_menu.select_uid(MENUID_DEV_TIMESTAMP, dev_timestmp);
7420 return D_O_K;
7421 }
7422 #if DEVLEVEL > 1
7423 int32_t setCheat()
7424 {
7425 cheat = (vbound(getnumber("Cheat Level",cheat), 0, 4));
7426 return D_O_K;
7427 }
7428 #endif //DEVLEVEL > 1
7429 #endif //DEVLEVEL > 0
7430
7431 enum
7432 {
7433 MENUID_PLAYER_CHEAT,
7434 };
7435
1/4
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
403 TopMenu the_player_menu
7436 2418 {
7437
2/4
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 403 times.
✗ Branch 3 not taken.
403 { "&Game", &game_menu },
7438
2/4
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 403 times.
✗ Branch 3 not taken.
403 { "&Settings", &settings_menu },
7439
2/4
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 403 times.
✗ Branch 3 not taken.
403 { "&Cheat", &cheat_menu, MENUID_PLAYER_CHEAT, true },
7440
2/4
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 403 times.
✗ Branch 3 not taken.
403 { "&Replay", &replay_menu },
7441
2/4
✓ Branch 0 taken 403 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 403 times.
✗ Branch 3 not taken.
403 { "&ZC", &misc_menu },
7442 #if DEVLEVEL > 0
7443 { "&Dev", &dev_menu },
7444 #endif
7445 };
7446
7447 int32_t onPauseInBackground()
7448 {
7449 if(jwin_alert3(
7450 "Toggle Pause In Background",
7451 "This action will change whether ZC Player pauses when the window loses focus.",
7452 "",
7453 "Proceed?",
7454 "&Yes",
7455 "&No",
7456 NULL,
7457 'y',
7458 'n',
7459 0,
7460 get_zc_font(font_lfont)) == 1)
7461 {
7462 pause_in_background = pause_in_background ? 0 : 1;
7463 zc_set_config("zeldadx","pause_in_background", pause_in_background);
7464 int switch_type = pause_in_background ? SWITCH_PAUSE : SWITCH_BACKGROUND;
7465 set_display_switch_mode(fullscreen?SWITCH_BACKAMNESIA:switch_type);
7466 set_display_switch_callback(SWITCH_OUT, switch_out_callback);
7467 set_display_switch_callback(SWITCH_IN, switch_in_callback);
7468 }
7469 options_menu.select_uid(MENUID_OPTIONS_PAUSE_BG, pause_in_background);
7470 return D_O_K;
7471 }
7472
7473 int32_t onKeyboardEntry()
7474 {
7475 NameEntryMode=0;
7476 zc_set_config(cfg_sect,"name_entry_mode",NameEntryMode);
7477 return D_O_K;
7478 }
7479
7480 int32_t onLetterGridEntry()
7481 {
7482 NameEntryMode=1;
7483 zc_set_config(cfg_sect,"name_entry_mode",NameEntryMode);
7484 return D_O_K;
7485 }
7486
7487 int32_t onExtLetterGridEntry()
7488 {
7489 NameEntryMode=2;
7490 zc_set_config(cfg_sect,"name_entry_mode",NameEntryMode);
7491 return D_O_K;
7492 }
7493
7494 static BITMAP* oldscreen;
7495 int32_t onFullscreenMenu()
7496 {
7497 PALETTE oldpal;
7498 get_palette(oldpal);
7499
7500 fullscreen = !fullscreen;
7501 all_toggle_fullscreen(fullscreen);
7502 zc_set_config("zeldadx","fullscreen",fullscreen);
7503
7504 zc_set_palette(oldpal);
7505 gui_mouse_focus=0;
7506 extern int32_t switch_type;
7507 switch_type = pause_in_background ? SWITCH_PAUSE : SWITCH_BACKGROUND;
7508 set_display_switch_mode(fullscreen?SWITCH_BACKAMNESIA:switch_type);
7509 set_display_switch_callback(SWITCH_OUT, switch_out_callback);
7510 set_display_switch_callback(SWITCH_IN, switch_in_callback);
7511 misc_menu.select_uid(MENUID_MISC_FULLSCREEN, isFullScreen());
7512 misc_menu.select_uid(MENUID_MISC_VIDMODE, isFullScreen());
7513
7514 return D_O_K;
7515 }
7516
7517 308 void fix_menu()
7518 {
7519
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 308 times.
308 if(!debug_enabled)
7520 308 settings_menu.chop_index = 13;
7521 308 }
7522
7523 int32_t onSetSnapshotFormat(SnapshotType format)
7524 {
7525 SnapshotFormat = format;
7526 zc_set_config("zeldadx", "snapshot_format", format);
7527 snapshot_format_menu.select_only_index(format);
7528 return D_O_K;
7529 }
7530
7531 int32_t onSetBottom8Pixels(int option)
7532 {
7533 ShowBottomPixels = option;
7534 zc_set_config("zeldadx", "bottom_8_px", option);
7535 bottom_8_pixels_menu.select_only_index(option);
7536
7537 int qr = qr_HIDE_BOTTOM_8_PIXELS;
7538 bool value = false;
7539 if (option == 0)
7540 value = get_bit(quest_rules, qr) != 0; // This is the original value, as set in the qst file (or via scripting).
7541 else if (option == 1)
7542 value = false;
7543 else if (option == 2)
7544 value = true;
7545 enqueue_qr_change(qr, value);
7546
7547 return D_O_K;
7548 }
7549
7550 2865 void updateShowBottomPixels()
7551 {
7552 // It's too tricky the allow modifying the screen height between opening and closing the
7553 // active subscreen.
7554
2/2
✓ Branch 0 taken 26 times.
✓ Branch 1 taken 2839 times.
2865 if (subscreen_open)
7555 26 return;
7556
7557
1/2
✓ Branch 0 taken 2839 times.
✗ Branch 1 not taken.
2839 if (!GameLoaded)
7558 show_bottom_8px = false;
7559 else
7560 2839 show_bottom_8px = !get_qr(qr_HIDE_BOTTOM_8_PIXELS);
7561
7562 2839 int target_bitmap_height = show_bottom_8px ? 232 : 224;
7563
2/2
✓ Branch 0 taken 2745 times.
✓ Branch 1 taken 94 times.
2839 if (framebuf->h != target_bitmap_height)
7564 {
7565 94 BITMAP* new_framebuf = create_bitmap_ex(8, 256, target_bitmap_height);
7566 94 clear_bitmap(new_framebuf);
7567 94 blit(framebuf, new_framebuf, 0, 0, 0, 0, new_framebuf->w, new_framebuf->h);
7568
7569 94 destroy_bitmap(framebuf);
7570 94 destroy_bitmap(script_menu_buf);
7571 94 destroy_bitmap(f6_menu_buf);
7572 94 destroy_bitmap(darkscr_bmp);
7573 94 destroy_bitmap(darkscr_bmp_trans);
7574
7575 94 framebuf = new_framebuf;
7576 94 script_menu_buf = create_bitmap_ex(8, 256, target_bitmap_height);
7577 94 f6_menu_buf = create_bitmap_ex(8, 256, target_bitmap_height);
7578 94 darkscr_bmp = create_bitmap_ex(8, 256, target_bitmap_height);
7579 94 darkscr_bmp_trans = create_bitmap_ex(8, 256, target_bitmap_height);
7580
7581 94 rti_game.a4_bitmap = framebuf;
7582 94 rti_game.set_size(framebuf->w, framebuf->h);
7583 94 al_set_new_bitmap_flags(ALLEGRO_CONVERT_BITMAP);
7584 94 al_destroy_bitmap(rti_game.bitmap);
7585 94 rti_game.bitmap = create_a5_bitmap(framebuf->w, framebuf->h);
7586 94 al_destroy_bitmap(rti_infolayer.bitmap);
7587 94 rti_infolayer.bitmap = create_a5_bitmap(framebuf->w, framebuf->h);
7588 94 }
7589 2865 }
7590
7591 void color_layer(RGB *src,RGB *dest,char r,char g,char b,char pos,int32_t from,int32_t to)
7592 {
7593 PALETTE tmp;
7594
7595 for(int32_t i=0; i<256; i++)
7596 {
7597 tmp[i].r=r;
7598 tmp[i].g=g;
7599 tmp[i].b=b;
7600 }
7601
7602 fade_interpolate(src,tmp,dest,pos,from,to);
7603 }
7604
7605 45 void system_pal(bool force)
7606 {
7607
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 45 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
45 if(is_sys_pal && !force) return;
7608 45 is_sys_pal = true;
7609 45 load_colorset(gui_colorset, syspal, jwin_a5_colors);
7610 45 hw_palette = &syspal;
7611 45 update_hw_pal = true;
7612 45 }
7613
7614 static uint32_t entered_sys_pal = 0;
7615 45 void enter_sys_pal()
7616 {
7617
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 45 times.
45 if(is_sys_pal)
7618 {
7619 if(entered_sys_pal)
7620 ++entered_sys_pal;
7621 return;
7622 }
7623 45 sys_mouse();
7624 45 system_pal(true);
7625 45 ++entered_sys_pal;
7626 45 }
7627 45 void exit_sys_pal()
7628 {
7629
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 45 times.
45 if(entered_sys_pal)
7630 {
7631
1/2
✓ Branch 0 taken 45 times.
✗ Branch 1 not taken.
45 if(!--entered_sys_pal)
7632 {
7633 45 game_pal();
7634 45 game_mouse();
7635 45 }
7636 45 }
7637 45 }
7638
7639 void switch_out_callback()
7640 {
7641 if (pause_in_background && !MenuOpen)
7642 {
7643 System();
7644 }
7645 }
7646
7647 void switch_in_callback()
7648 {
7649 }
7650
7651 1127 void game_pal()
7652 {
7653 1127 is_sys_pal = false;
7654 1127 entered_sys_pal = 0;
7655 1127 hw_palette = &RAMpal;
7656 1127 update_hw_pal = true;
7657 1127 }
7658
7659 static char bar_str[] = "";
7660
7661 45 void music_pause()
7662 {
7663 //al_pause_duh(tmplayer);
7664 45 zcmusic_pause(zcmusic, ZCM_PAUSE);
7665
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 45 times.
45 if(zcmixer->oldtrack)
7666 zcmusic_pause(zcmixer->oldtrack, ZCM_PAUSE);
7667 45 zc_midi_pause();
7668 45 }
7669
7670 void music_resume()
7671 {
7672 //al_resume_duh(tmplayer);
7673 zcmusic_pause(zcmusic, ZCM_RESUME);
7674 if (zcmixer->oldtrack)
7675 zcmusic_pause(zcmixer->oldtrack, ZCM_RESUME);
7676 zc_midi_resume();
7677 }
7678
7679 7808 void music_stop()
7680 {
7681 //al_stop_duh(tmplayer);
7682 //unload_duh(tmusic);
7683 //tmusic=NULL;
7684 //tmplayer=NULL;
7685 7808 zcmusic_stop(zcmusic);
7686 7808 zcmusic_unload_file(zcmusic);
7687
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7808 times.
7808 if (zcmixer->oldtrack)
7688 {
7689 zcmusic_stop(zcmixer->oldtrack);
7690 zcmusic_unload_file(zcmixer->oldtrack);
7691 }
7692 7808 zcmixer->newtrack = NULL;
7693 7808 zc_stop_midi();
7694 7808 currmidi=-1;
7695 7808 }
7696
7697 bool reload_fonts = false;
7698 void System()
7699 {
7700 mouse_down = gui_mouse_b();
7701 music_pause();
7702 pause_all_sfx();
7703 MenuOpen = true;
7704 enter_sys_pal();
7705 // FONT *oldfont=font;
7706 // font=tfont;
7707
7708 misc_menu.select_uid(MENUID_MISC_FULLSCREEN, isFullScreen());
7709 misc_menu.disable_uid(MENUID_MISC_VIDMODE, isFullScreen());
7710
7711 #if DEVLEVEL > 1
7712 dev_menu.disable_uid(MENUID_DEV_SETCHEAT, !Playing);
7713 #endif
7714 game_menu.disable_uid(MENUID_GAME_LOADQUEST, get_unset_save_slot());
7715 game_menu.disable_uid(MENUID_GAME_ENDGAME, !Playing);
7716 misc_menu.disable_uid(MENUID_MISC_QUEST_INFO, !Playing);
7717 misc_menu.disable_uid(MENUID_MISC_QUEST_DIR, Playing);
7718 clear_keybuf();
7719
7720 clear_bitmap(menu_bmp);
7721 oldscreen = screen;
7722 screen = menu_bmp;
7723
7724 the_player_menu.reset_state();
7725 the_player_menu.position(0, 0);
7726
7727 bool running = true;
7728 bool esc = key[KEY_ESC] || cMbtn();
7729 bool autopop = esc;
7730 do
7731 {
7732 if(reload_fonts)
7733 {
7734 init_custom_fonts();
7735 clear_bitmap(menu_bmp);
7736 broadcast_dialog_message(MSG_DRAW, 0);
7737 reload_fonts = false;
7738 }
7739 if(handle_close_btn_quit())
7740 break;
7741
7742 //update submenus
7743 {
7744 settings_menu.disable_uid(MENUID_SETTINGS_CONTROLS, replay_is_replaying());
7745 settings_menu.select_uid(MENUID_SETTINGS_CAPFPS, Throttlefps);
7746 settings_menu.select_uid(MENUID_SETTINGS_SHOWFPS, ShowFPS);
7747 settings_menu.select_uid(MENUID_SETTINGS_SHOWTIME, ShowGameTime);
7748 settings_menu.select_uid(MENUID_SETTINGS_CLICK_FREEZE, ClickToFreeze);
7749 settings_menu.select_uid(MENUID_SETTINGS_TRANSLAYERS, TransLayers);
7750 settings_menu.select_uid(MENUID_SETTINGS_NESQUIT, NESquit);
7751 settings_menu.select_uid(MENUID_SETTINGS_VOLKEYS, volkeys);
7752
7753 window_menu.select_uid(MENUID_WINDOW_LOCK_ASPECT, DragAspect);
7754 window_menu.select_uid(MENUID_WINDOW_LOCK_INTSCALE, scaleForceInteger);
7755 window_menu.select_uid(MENUID_WINDOW_SAVE_SIZE, SaveDragResize);
7756 window_menu.select_uid(MENUID_WINDOW_SAVE_POS, SaveWinPos);
7757 window_menu.select_uid(MENUID_WINDOW_STRETCH, stretchGame);
7758
7759 options_menu.select_uid(MENUID_OPTIONS_EPILEPSYPROT, epilepsyFlashReduction);
7760 options_menu.select_uid(MENUID_OPTIONS_PAUSE_BG, pause_in_background);
7761 options_menu.disable_uid(MENUID_OPTIONS_SHOWBOTTOMPIXELS, replay_is_replaying());
7762
7763 name_entry_mode_menu.select_only_index(NameEntryMode);
7764
7765 misc_menu.select_uid(MENUID_MISC_CONSOLE, console_enabled);
7766 misc_menu.select_uid(MENUID_MISC_CLEAR_CONSOLE_ON_LOAD, clearConsoleOnLoad);
7767
7768 bool nocheat = (replay_is_replaying() || !Playing
7769 || (!maxcheat && !zcheats.flags && !get_debug() && DEVLEVEL < 2 && !zqtesting_mode && !devpwd()));
7770 the_player_menu.disable_uid(MENUID_PLAYER_CHEAT, nocheat);
7771 refill_menu.disable_uid(MENUID_REFILL_ARROWS, !get_qr(qr_TRUEARROWS));
7772 cheat_menu.chop_index.reset();
7773 if(cheat < 4)
7774 cheat_menu.chop_index = cheat_menu.ind_at(MENUID_CHEAT_CHOP_L1+cheat);
7775 cheat_menu.select_uid(MENUID_CHEAT_INVULN, getClock());
7776 cheat_menu.select_uid(MENUID_CHEAT_NOCLIP, toogam);
7777 cheat_menu.select_uid(MENUID_CHEAT_IGNORESV, ignoreSideview);
7778 cheat_menu.select_uid(MENUID_CHEAT_GOFAST, gofast);
7779
7780 show_menu.select_uid(MENUID_SHOW_L0, show_layers[0]);
7781 show_menu.select_uid(MENUID_SHOW_L1, show_layers[1]);
7782 show_menu.select_uid(MENUID_SHOW_L2, show_layers[2]);
7783 show_menu.select_uid(MENUID_SHOW_L3, show_layers[3]);
7784 show_menu.select_uid(MENUID_SHOW_L4, show_layers[4]);
7785 show_menu.select_uid(MENUID_SHOW_L5, show_layers[5]);
7786 show_menu.select_uid(MENUID_SHOW_L6, show_layers[6]);
7787 show_menu.select_uid(MENUID_SHOW_OVER, show_layer_over);
7788 show_menu.select_uid(MENUID_SHOW_PUSH, show_layer_push);
7789 show_menu.select_uid(MENUID_SHOW_SPR, show_sprites);
7790 show_menu.select_uid(MENUID_SHOW_FFC, show_ffcs);
7791 show_menu.select_uid(MENUID_SHOW_SOLIDITY, show_walkflags);
7792 show_menu.select_uid(MENUID_SHOW_SCRIPTNAME, show_ff_scripts);
7793 show_menu.select_uid(MENUID_SHOW_HITBOX, show_hitboxes);
7794 show_menu.select_uid(MENUID_SHOW_EFFECT, show_effectflags);
7795
7796 settings_menu.select_uid(MENUID_SETTINGS_HEARTBEEP, heart_beep);
7797 settings_menu.select_uid(MENUID_SETTINGS_SAVEINDICATOR, use_save_indicator);
7798
7799 replay_menu.by_uid(MENUID_REPLAY_STOP)->text = fmt::format("Stop {}",
7800 replay_get_mode() == ReplayMode::Record ? "recording" : "replaying");
7801
7802 replay_menu.select_uid(MENUID_REPLAY_RECORDNEW, zc_get_config("zeldadx", "replay_new_saves", false));
7803 #ifdef HAS_CURL
7804 replay_menu.select_uid(MENUID_REPLAY_AUTOUPLOAD, replay_upload_auto_enabled());
7805 #endif
7806 replay_menu.disable_uid(MENUID_REPLAY_STOP, !replay_is_active());
7807 replay_menu.disable_uid(MENUID_REPLAY_SAVE, replay_get_mode() != ReplayMode::Record);
7808 replay_menu.select_uid(MENUID_REPLAY_SNAP_ALL, replay_is_snapshot_all_frames());
7809
7810 snapshot_format_menu.select_only_index(SnapshotFormat);
7811 bottom_8_pixels_menu.select_only_index(ShowBottomPixels);
7812 }
7813
7814 if(debug_enabled)
7815 settings_menu.select_uid(MENUID_SETTINGS_DEBUG, get_debug());
7816
7817 if(autopop)
7818 clear_keybuf();
7819 the_player_menu.run(true);
7820 if(autopop)
7821 {
7822 the_player_menu.pop_sub(0, &the_player_menu);
7823 the_player_menu.draw(screen, the_player_menu.hovered_ind());
7824 autopop = false;
7825 update_hw_screen();
7826 }
7827
7828 update_hw_screen();
7829
7830 auto mb = gui_mouse_b();
7831 if(XOR(mb, mouse_down))
7832 {
7833 if(!the_player_menu.has_mouse())
7834 if(mb)
7835 break;
7836 mouse_down = mb;
7837 }
7838
7839 if(input_idle(true) > after_time())
7840 // run Screeen Saver
7841 {
7842 // Screen saver enabled for now.
7843 clear_keybuf();
7844 Matrix(ss_speed, ss_density, 0);
7845 system_pal(true);
7846 sys_mouse();
7847 }
7848
7849 poll_keyboard();
7850 if(esc)
7851 {
7852 if(!key[KEY_ESC])
7853 esc = false;
7854 }
7855
7856 if(keypressed() && !CHECK_ALT) //System hotkeys
7857 {
7858 auto c = peekkey();
7859 bool eatkey = true;
7860 switch(c>>8)
7861 {
7862 //Spare keys used by the menu
7863 case KEY_UP:
7864 case KEY_DOWN:
7865 case KEY_LEFT:
7866 case KEY_RIGHT:
7867 eatkey = false;
7868 break;
7869 case KEY_F1:
7870 onThrottleFPS();
7871 break;
7872 case KEY_F2:
7873 onShowFPS();
7874 break;
7875 case KEY_F6:
7876 onTryQuitMenu();
7877 break;
7878 #ifndef ALLEGRO_MACOSX
7879 case KEY_F9:
7880 onReset();
7881 break;
7882 case KEY_F10:
7883 onExit();
7884 break;
7885 #else
7886 case KEY_F7:
7887 onReset();
7888 break;
7889 case KEY_F8:
7890 onExit();
7891 break;
7892 #endif
7893 case KEY_F12:
7894 onSnapshot();
7895 break;
7896 case KEY_TAB:
7897 onDebug();
7898 break;
7899 case KEY_ESC:
7900 if(!esc)
7901 running = false;
7902 break;
7903 }
7904 if(eatkey)
7905 readkey();
7906 }
7907 if(Quit || (GameFlags & GAMEFLAG_TRYQUIT))
7908 break;
7909 }
7910 while(running);
7911
7912 screen = oldscreen;
7913
7914 mouse_down=gui_mouse_b();
7915 MenuOpen = false;
7916 if(Quit)
7917 {
7918 kill_sfx();
7919 music_stop();
7920 update_hw_screen();
7921 }
7922 else
7923 {
7924 music_resume();
7925 resume_all_sfx();
7926
7927 if(rc)
7928 ringcolor(false);
7929 }
7930 exit_sys_pal();
7931
7932 eat_buttons();
7933
7934 rc=false;
7935 clear_keybuf();
7936
7937 zc_init_apply_cheat_delta();
7938 }
7939
7940 308 void fix_dialogs()
7941 {
7942 308 jwin_center_dialog(about_dlg);
7943 308 jwin_center_dialog(gamepad_dlg);
7944 308 jwin_center_dialog(credits_dlg);
7945 308 jwin_center_dialog(gamemode_dlg);
7946 308 jwin_center_dialog(getnum_dlg);
7947 308 jwin_center_dialog(goto_dlg);
7948 308 jwin_center_dialog(keyboard_control_dlg);
7949 308 jwin_center_dialog(midi_dlg);
7950 308 jwin_center_dialog(quest_dlg);
7951 308 jwin_center_dialog(scrsaver_dlg);
7952 308 jwin_center_dialog(sound_dlg);
7953 308 jwin_center_dialog(triforce_dlg);
7954 308 }
7955
7956 4324 INLINE int32_t mixvol(int32_t v1,int32_t v2)
7957 {
7958
3/4
✓ Branch 0 taken 4324 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4302 times.
✓ Branch 3 taken 22 times.
4324 return (zc_min(v1,255)*zc_min(v2,255)) >> 8;
7959 }
7960
7961 292 int32_t get_emusic_volume()
7962 {
7963 292 int32_t temp_volume = emusic_volume;
7964
2/4
✓ Branch 0 taken 292 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 292 times.
✗ Branch 3 not taken.
292 if (GameLoaded && !get_qr(qr_OLD_SCRIPT_VOLUME))
7965 temp_volume = (emusic_volume * FFCore.usr_music_volume) / 10000 / 100;
7966
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 292 times.
292 if (!zcmusic)
7967 292 return temp_volume;
7968 return (temp_volume * zcmusic->fadevolume) / 10000;
7969 292 }
7970
7971 int32_t get_zcmusicpos()
7972 {
7973 int32_t debugtracething = zcmusic_get_curpos(zcmusic);
7974 return debugtracething;
7975 return 0;
7976 }
7977
7978 void set_zcmusicpos(int32_t position)
7979 {
7980 zcmusic_set_curpos(zcmusic, position);
7981 }
7982
7983 void set_zcmusicspeed(int32_t speed)
7984 {
7985 zcmusic_set_speed(zcmusic, speed);
7986 }
7987
7988 int32_t get_zcmusiclen()
7989 {
7990 return zcmusic_get_length(zcmusic);
7991 }
7992
7993 3 void set_zcmusicloop(double start, double end)
7994 {
7995 3 zcmusic_set_loop(zcmusic, start, end);
7996 3 }
7997
7998 64156 void jukebox(int32_t index,int32_t loop)
7999 {
8000
1/2
✓ Branch 0 taken 64156 times.
✗ Branch 1 not taken.
64156 if (is_headless())
8001 64156 return;
8002
8003 music_stop();
8004
8005 if(index<0) index=MAXMIDIS-1;
8006
8007 if(index>=MAXMIDIS) index=0;
8008
8009 music_stop();
8010
8011 // Allegro's DIGMID driver (the one normally used on on Linux) gets
8012 // stuck notes when a song stops. This fixes it.
8013 if(strcmp(midi_driver->name, "DIGMID")==0)
8014 zc_set_volume(0, 0);
8015
8016 zc_set_volume(-1, mixvol(tunes[index].volume, midi_volume >>1));
8017 zc_play_midi(tunes[index].data,loop);
8018
8019 if(tunes[index].start>0)
8020 zc_midi_seek(tunes[index].start);
8021
8022 midi_loop_start = tunes[index].loop_start;
8023 midi_loop_end = tunes[index].loop_end;
8024
8025 currmidi=index;
8026 master_volume(digi_volume, midi_volume);
8027 //midi_paused=false;
8028 64156 }
8029
8030 64156 void jukebox(int32_t index)
8031 {
8032
1/2
✓ Branch 0 taken 64156 times.
✗ Branch 1 not taken.
64156 if(index<0) index=MAXMIDIS-1;
8033
8034
1/2
✓ Branch 0 taken 64156 times.
✗ Branch 1 not taken.
64156 if(index>=MAXMIDIS) index=0;
8035
8036 // do nothing if it's already playing
8037
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 64156 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
64156 if(index==currmidi && midi_pos>=0)
8038 {
8039 return;
8040 }
8041
8042 64156 jukebox(index,tunes[index].loop);
8043 64156 }
8044
8045 100 void play_DmapMusic()
8046 {
8047
1/2
✓ Branch 0 taken 100 times.
✗ Branch 1 not taken.
100 if (is_headless())
8048 100 return;
8049
8050 static char tfile[2048];
8051 static int32_t ttrack=0;
8052 bool domidi=false;
8053
8054 int32_t fadeoutframes = 0;
8055 if (zcmusic != NULL)
8056 fadeoutframes = zcmusic->fadeoutframes;
8057
8058 if(DMaps[cur_dmap].tmusic[0]!=0)
8059 {
8060 if(zcmusic==NULL ||
8061 strcmp(zcmusic->filename,DMaps[cur_dmap].tmusic)!=0 ||
8062 (zcmusic->type==ZCMF_GME && zcmusic->track != DMaps[cur_dmap].tmusictrack))
8063 {
8064 if (DMaps[cur_dmap].tmusic_xfade_in > 0 || fadeoutframes > 0)
8065 {
8066 if (play_enh_music_crossfade(DMaps[cur_dmap].tmusic, qstpath, DMaps[cur_dmap].tmusictrack, get_emusic_volume(), DMaps[cur_dmap].tmusic_xfade_in, fadeoutframes))
8067 {
8068 if (zcmusic != NULL)
8069 {
8070 zcmusic->fadeoutframes = DMaps[cur_dmap].tmusic_xfade_out;
8071 zcmusic_set_loop(zcmusic, double(DMaps[cur_dmap].tmusic_loop_start / 10000.0), double(DMaps[cur_dmap].tmusic_loop_end / 10000.0));
8072 }
8073 }
8074 }
8075 else
8076 {
8077 if (zcmusic != NULL)
8078 {
8079 zcmusic_stop(zcmusic);
8080 zcmusic_unload_file(zcmusic);
8081 zcmusic = NULL;
8082 zcmixer->newtrack = NULL;
8083 }
8084
8085 zcmusic = zcmusic_load_for_quest(DMaps[cur_dmap].tmusic, qstpath).first;
8086 zcmixer->newtrack = zcmusic;
8087
8088 if (zcmusic != NULL)
8089 {
8090 zc_stop_midi();
8091 strcpy(tfile, DMaps[cur_dmap].tmusic);
8092 zcmusic_play(zcmusic, emusic_volume);
8093 int32_t temptracks = 0;
8094 temptracks = zcmusic_get_tracks(zcmusic);
8095 temptracks = (temptracks < 2) ? 1 : temptracks;
8096 ttrack = vbound(DMaps[cur_dmap].tmusictrack, 0, temptracks - 1);
8097 zcmusic_change_track(zcmusic, ttrack);
8098 zcmusic_set_loop(zcmusic, double(DMaps[cur_dmap].tmusic_loop_start / 10000.0), double(DMaps[cur_dmap].tmusic_loop_end / 10000.0));
8099 }
8100 else
8101 {
8102 tfile[0] = 0;
8103 domidi = true;
8104 }
8105 }
8106 }
8107 }
8108 else
8109 {
8110 if (DMaps[cur_dmap].midi == 0 && fadeoutframes > 0 && zcmusic != NULL && strcmp(zcmusic->filename, DMaps[cur_dmap].tmusic) != 0)
8111 {
8112 play_enh_music_crossfade(NULL, qstpath, DMaps[cur_dmap].tmusictrack, get_emusic_volume(), DMaps[cur_dmap].tmusic_xfade_in, fadeoutframes);
8113 }
8114 else
8115 {
8116 domidi = true;
8117 }
8118 }
8119
8120 if(domidi)
8121 {
8122 int32_t m=DMaps[cur_dmap].midi;
8123
8124 switch(m)
8125 {
8126 case 1:
8127 jukebox(ZC_MIDI_OVERWORLD);
8128 break;
8129
8130 case 2:
8131 jukebox(ZC_MIDI_DUNGEON);
8132 break;
8133
8134 case 3:
8135 jukebox(ZC_MIDI_LEVEL9);
8136 break;
8137
8138 default:
8139 if(m>=4 && m<4+MAXCUSTOMMIDIS)
8140 jukebox(m+MIDIOFFSET_DMAP);
8141 else
8142 music_stop();
8143 }
8144 }
8145 100 }
8146
8147 35353 void playLevelMusic()
8148 {
8149
1/2
✓ Branch 0 taken 35353 times.
✗ Branch 1 not taken.
35353 if (is_headless())
8150 35353 return;
8151
8152 int32_t m=hero_scr->screen_midi;
8153
8154 switch(m)
8155 {
8156 case -2:
8157 music_stop();
8158 break;
8159
8160 case -1:
8161 play_DmapMusic();
8162 break;
8163
8164 case 1:
8165 jukebox(ZC_MIDI_OVERWORLD);
8166 break;
8167
8168 case 2:
8169 jukebox(ZC_MIDI_DUNGEON);
8170 break;
8171
8172 case 3:
8173 jukebox(ZC_MIDI_LEVEL9);
8174 break;
8175
8176 default:
8177 if(m>=4 && m<4+MAXCUSTOMMIDIS)
8178 jukebox(m+MIDIOFFSET_MAPSCR);
8179 else
8180 music_stop();
8181 }
8182 35353 }
8183
8184 4324 void master_volume(int32_t dv,int32_t mv)
8185 {
8186
7/8
✓ Branch 0 taken 2008 times.
✓ Branch 1 taken 2316 times.
✓ Branch 2 taken 1967 times.
✓ Branch 3 taken 349 times.
✓ Branch 4 taken 2316 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1967 times.
✓ Branch 7 taken 349 times.
4324 if(dv>=0) digi_volume=zc_max(zc_min(dv,255),0);
8187
8188
7/8
✓ Branch 0 taken 2004 times.
✓ Branch 1 taken 2320 times.
✓ Branch 2 taken 2000 times.
✓ Branch 3 taken 320 times.
✓ Branch 4 taken 2320 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2000 times.
✓ Branch 7 taken 320 times.
4324 if(mv>=0) midi_volume=zc_max(zc_min(mv,255),0);
8189
8190
3/6
✗ Branch 0 not taken.
✓ Branch 1 taken 4324 times.
✓ Branch 2 taken 4324 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 4324 times.
4324 int32_t i = zc_min(zc_max(currmidi,0),MAXMIDIS-1);
8191 4324 int32_t temp_vol = midi_volume;
8192
2/2
✓ Branch 0 taken 4016 times.
✓ Branch 1 taken 308 times.
4324 if (!get_qr(qr_OLD_SCRIPT_VOLUME))
8193 308 temp_vol = (midi_volume * FFCore.usr_music_volume) / 10000 / 100;
8194 4324 zc_set_volume(digi_volume,mixvol(tunes[i].volume, temp_vol));
8195 4324 }
8196
8197 // array of voices, one for each sfx sample in the data file
8198 // 0+ = voice #
8199 // -1 = voice not allocated
8200 308 void Z_init_sound()
8201 {
8202
2/2
✓ Branch 0 taken 78848 times.
✓ Branch 1 taken 308 times.
79156 for(int32_t i=0; i<WAV_COUNT; i++)
8203 78848 sfx_voice[i]=-1;
8204
8205 308 const char* midis[ZC_MIDI_COUNT] = {
8206 "assets/dungeon.mid",
8207 "assets/ending.mid",
8208 "assets/gameover.mid",
8209 "assets/level9.mid",
8210 "assets/overworld.mid",
8211 "assets/title.mid",
8212 "assets/triforce.mid",
8213 };
8214
2/2
✓ Branch 0 taken 2156 times.
✓ Branch 1 taken 308 times.
2464 for(int32_t i=0; i<ZC_MIDI_COUNT; i++)
8215 {
8216 2156 tunes[i].data = load_midi(midis[i]);
8217
1/2
✓ Branch 0 taken 2156 times.
✗ Branch 1 not taken.
2156 if (!tunes[i].data)
8218 Z_error_fatal("Missing required file %s\n", midis[i]);
8219 2156 }
8220
8221
2/2
✓ Branch 0 taken 77616 times.
✓ Branch 1 taken 308 times.
77924 for(int32_t j=0; j<MAXCUSTOMMIDIS; j++)
8222 77616 tunes[ZC_MIDI_COUNT+j].data=NULL;
8223
8224 308 master_volume(digi_volume,midi_volume);
8225 308 }
8226
8227 // returns number of voices currently allocated
8228 int32_t sfx_count()
8229 {
8230 int32_t c=0;
8231
8232 for(int32_t i=0; i<WAV_COUNT; i++)
8233 if(sfx_voice[i]!=-1)
8234 ++c;
8235
8236 return c;
8237 }
8238
8239 // clean up finished samples
8240 18131310 void sfx_cleanup()
8241 {
8242
2/2
✓ Branch 0 taken 4641615360 times.
✓ Branch 1 taken 18131310 times.
4659746670 for(int32_t i=0; i<WAV_COUNT; i++)
8243
3/4
✓ Branch 0 taken 1256696 times.
✓ Branch 1 taken 4640358664 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1256696 times.
4642872056 if(sfx_voice[i]!=-1 && voice_get_position(sfx_voice[i])<0)
8244 {
8245 1256696 deallocate_voice(sfx_voice[i]);
8246 1256696 sfx_voice[i]=-1;
8247 1256696 }
8248 18131310 }
8249
8250 1256851 SAMPLE* sfx_get_sample(int32_t index)
8251 {
8252 // check index
8253
2/4
✓ Branch 0 taken 1256851 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1256851 times.
1256851 if (index<=0 || index>=WAV_COUNT)
8254 return nullptr;
8255
8256
2/2
✓ Branch 0 taken 436140 times.
✓ Branch 1 taken 820711 times.
1256851 if (sfxdat)
8257 {
8258
1/2
✓ Branch 0 taken 436140 times.
✗ Branch 1 not taken.
436140 if (index<Z35)
8259 {
8260 436140 return (SAMPLE*)sfxdata[index].dat;
8261 }
8262 else
8263 {
8264 return (SAMPLE*)sfxdata[Z35].dat;
8265 }
8266 }
8267 else
8268 {
8269 820711 return &customsfxdata[index];
8270 }
8271
8272 return nullptr;
8273 1256851 }
8274
8275 // allocates a voice for the sample "wav_index" (index into zelda.dat)
8276 // if a voice is already allocated (and/or playing), then it just returns true
8277 // Returns true: voice is allocated
8278 // false: unsuccessful
8279 1861212 bool sfx_init(int32_t index)
8280 {
8281 // check index
8282
3/4
✓ Branch 0 taken 1388926 times.
✓ Branch 1 taken 472286 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1388926 times.
1861212 if(index<=0 || index>=WAV_COUNT)
8283 472286 return false;
8284
8285
2/2
✓ Branch 0 taken 132126 times.
✓ Branch 1 taken 1256800 times.
1388926 if (sfx_voice[index] == -1)
8286 {
8287 1256800 SAMPLE* sample = sfx_get_sample(index);
8288
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1256800 times.
1256800 if (!sample)
8289 return false;
8290
8291 1256800 sfx_voice[index] = allocate_voice(sample);
8292 1256800 }
8293
8294 1388926 return sfx_voice[index] != -1;
8295 1861212 }
8296
8297 int32_t sfx_get_default_freq(int32_t index)
8298 {
8299 if (sfxdat)
8300 {
8301 if (index < Z35)
8302 {
8303 return ((SAMPLE*)sfxdata[index].dat)->freq;
8304 }
8305 else
8306 {
8307 return ((SAMPLE*)sfxdata[Z35].dat)->freq;
8308 }
8309 }
8310 else
8311 {
8312 return customsfxdata[index].freq;
8313 }
8314 }
8315
8316 int32_t sfx_get_length(int32_t index)
8317 {
8318 if (sfxdat)
8319 {
8320 if (index < Z35)
8321 {
8322 return int32_t(((SAMPLE*)sfxdata[index].dat)->len);
8323 }
8324 else
8325 {
8326 return int32_t(((SAMPLE*)sfxdata[Z35].dat)->len);
8327 }
8328 }
8329 else
8330 {
8331 return int32_t(customsfxdata[index].len);
8332 }
8333 }
8334
8335 // plays an sfx sample
8336 1861212 void sfx(int32_t index,int32_t pan,bool loop, bool restart, int32_t vol, int32_t freq)
8337 {
8338
2/2
✓ Branch 0 taken 1388926 times.
✓ Branch 1 taken 472286 times.
1861212 if(!sfx_init(index))
8339 472286 return;
8340
1/2
✓ Branch 0 taken 1388926 times.
✗ Branch 1 not taken.
1388926 if (!is_headless())
8341 {
8342 voice_set_playmode(sfx_voice[index], loop ? PLAYMODE_LOOP : PLAYMODE_PLAY);
8343 voice_set_pan(sfx_voice[index], pan);
8344
8345 // Only used by ZScript currently
8346 if (freq <= -1)
8347 {
8348 freq = sfx_get_default_freq(index);
8349 }
8350 voice_set_frequency(sfx_voice[index], freq);
8351
8352 // Only used by ZScript currently
8353 int32_t temp_volume = (sfx_volume * vol) / 10000 / 100;
8354 if (GameLoaded && !get_qr(qr_OLD_SCRIPT_VOLUME))
8355 temp_volume = (temp_volume * FFCore.usr_sfx_volume) / 10000 / 100;
8356 voice_set_volume(sfx_voice[index], temp_volume);
8357
8358 int32_t pos = voice_get_position(sfx_voice[index]);
8359
8360 if (restart) voice_set_position(sfx_voice[index], 0);
8361
8362 if (pos <= 0)
8363 voice_start(sfx_voice[index]);
8364 }
8365
8366
3/4
✓ Branch 0 taken 855488 times.
✓ Branch 1 taken 533438 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 855488 times.
1388926 if (restart && replay_is_debug())
8367 {
8368 // TODO(replays): get rid of this bandaid next time replays are mass-updated.
8369 855488 const char* sfx_name = sfx_string[index];
8370
2/2
✓ Branch 0 taken 844104 times.
✓ Branch 1 taken 11384 times.
855488 if (strcmp(sfx_name, "Hero is hit") == 0)
8371 11384 sfx_name = "Player is hit";
8372
2/2
✓ Branch 0 taken 843985 times.
✓ Branch 1 taken 119 times.
844104 else if (strcmp(sfx_name, "Hero dies") == 0)
8373 119 sfx_name = "Player dies";
8374
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 855488 times.
855488 replay_step_comment(fmt::format("sfx {}", sfx_name));
8375 855488 }
8376 1861212 }
8377
8378 // true if sfx is allocated
8379 197319 bool sfx_allocated(int32_t index)
8380 {
8381
3/4
✓ Branch 0 taken 33546 times.
✓ Branch 1 taken 163773 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 33546 times.
197319 return (index>0 && index<WAV_COUNT && sfx_voice[index]!=-1);
8382 }
8383
8384 // start it (in loop mode) if it's not already playing,
8385 // otherwise adjust it to play in loop mode -DD
8386 117265 void cont_sfx(int32_t index)
8387 {
8388
1/2
✓ Branch 0 taken 117265 times.
✗ Branch 1 not taken.
117265 if (is_headless())
8389 117265 return;
8390
8391 if(!sfx_init(index))
8392 {
8393 return;
8394 }
8395
8396 if(voice_get_position(sfx_voice[index])<=0)
8397 {
8398 voice_set_position(sfx_voice[index],0);
8399 voice_set_playmode(sfx_voice[index],PLAYMODE_LOOP);
8400 voice_set_volume(sfx_voice[index], sfx_volume);
8401 voice_start(sfx_voice[index]);
8402 }
8403 else
8404 {
8405 adjust_sfx(index, 128, true);
8406 }
8407 117265 }
8408
8409 // adjust parameters while playing
8410 5294 void adjust_sfx(int32_t index,int32_t pan,bool loop)
8411 {
8412
4/6
✓ Branch 0 taken 4461 times.
✓ Branch 1 taken 833 times.
✓ Branch 2 taken 4461 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 4461 times.
5294 if(index<=0 || index>=WAV_COUNT || sfx_voice[index]==-1)
8413 5294 return;
8414
8415 voice_set_playmode(sfx_voice[index],loop?PLAYMODE_LOOP:PLAYMODE_PLAY);
8416 voice_set_pan(sfx_voice[index],pan);
8417 5294 }
8418
8419 // pauses a voice
8420 3191 void pause_sfx(int32_t index)
8421 {
8422
3/6
✓ Branch 0 taken 3191 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3191 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 3191 times.
3191 if(index>0 && index<WAV_COUNT && sfx_voice[index]!=-1)
8423 voice_stop(sfx_voice[index]);
8424 3191 }
8425
8426 // resumes a voice
8427 1351 void resume_sfx(int32_t index)
8428 {
8429
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1351 times.
1351 if (is_headless())
8430 1351 return;
8431
8432 if(index>0 && index<WAV_COUNT && sfx_voice[index]!=-1)
8433 voice_start(sfx_voice[index]);
8434 1351 }
8435
8436 // pauses all active voices
8437 1062 void pause_all_sfx()
8438 {
8439
2/2
✓ Branch 0 taken 271872 times.
✓ Branch 1 taken 1062 times.
272934 for(int32_t i=0; i<WAV_COUNT; i++)
8440
2/2
✓ Branch 0 taken 271870 times.
✓ Branch 1 taken 2 times.
271874 if(sfx_voice[i]!=-1)
8441 2 voice_stop(sfx_voice[i]);
8442 1062 }
8443
8444 // resumes all paused voices
8445 1017 void resume_all_sfx()
8446 {
8447
2/2
✓ Branch 0 taken 260352 times.
✓ Branch 1 taken 1017 times.
261369 for(int32_t i=0; i<WAV_COUNT; i++)
8448
1/2
✓ Branch 0 taken 260352 times.
✗ Branch 1 not taken.
260352 if(sfx_voice[i]!=-1)
8449 voice_start(sfx_voice[i]);
8450 1017 }
8451
8452 // stops an sfx and deallocates the voice
8453 14469956 void stop_sfx(int32_t index)
8454 {
8455
3/4
✓ Branch 0 taken 14224237 times.
✓ Branch 1 taken 245719 times.
✓ Branch 2 taken 14224237 times.
✗ Branch 3 not taken.
14469956 if(index<=0 || index>=WAV_COUNT)
8456 245719 return;
8457
8458
2/2
✓ Branch 0 taken 47 times.
✓ Branch 1 taken 14224190 times.
14224237 if(sfx_voice[index]!=-1)
8459 {
8460 47 deallocate_voice(sfx_voice[index]);
8461 47 sfx_voice[index]=-1;
8462 47 }
8463 14469956 }
8464
8465 // Stops SFX played by Hero's item of the given family
8466 162789 void stop_item_sfx(int32_t family)
8467 {
8468 162789 int32_t id=current_item_id(family);
8469
8470
2/2
✓ Branch 0 taken 161689 times.
✓ Branch 1 taken 1100 times.
162789 if(id<0)
8471 161689 return;
8472
8473 1100 stop_sfx(itemsbuf[id].usesound);
8474 162789 }
8475
8476 9218 void kill_sfx()
8477 {
8478
2/2
✓ Branch 0 taken 2359808 times.
✓ Branch 1 taken 9218 times.
2369026 for(int32_t i=0; i<WAV_COUNT; i++)
8479
2/2
✓ Branch 0 taken 2359751 times.
✓ Branch 1 taken 57 times.
2359865 if(sfx_voice[i]!=-1)
8480 {
8481 57 deallocate_voice(sfx_voice[i]);
8482 57 sfx_voice[i]=-1;
8483 57 }
8484 9218 }
8485
8486 // TODO: when far out of bounds, sounds should dampen. currently we only pan.
8487 1166510 int32_t pan(int32_t x)
8488 {
8489
1/5
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 1166510 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
1166510 switch(pan_style)
8490 {
8491 // MONO
8492 case 0:
8493 return 128;
8494
8495 // 1/2
8496 case 1:
8497 1166510 x -= viewport.x;
8498 1166510 return vbound((x>>1)+68,0,255);
8499
8500 // 3/4
8501 case 2:
8502 x -= viewport.x;
8503 return vbound(((x*3)>>2)+36,0,255);
8504
8505 // FULL
8506 case 3:
8507 default:
8508 x -= viewport.x;
8509 return vbound(x,0,255);
8510 }
8511 1166510 }
8512
8513 49960667 bool joybtn(int32_t b)
8514 {
8515
1/2
✓ Branch 0 taken 49960667 times.
✗ Branch 1 not taken.
49960667 if(b == 0)
8516 return false;
8517
1/2
✓ Branch 0 taken 49960667 times.
✗ Branch 1 not taken.
49960667 if (b-1 >= joy[joystick_index].num_buttons)
8518 49960667 return false;
8519
8520 return joy[joystick_index].button[b-1].b !=0;
8521 49960667 }
8522
8523 bool joystick(int32_t s)
8524 {
8525 if(s < 0)
8526 return false;
8527 if (s >= joy[joystick_index].num_sticks)
8528 return false;
8529
8530 for (int i = 0; i < joy[joystick_index].stick[s].num_axis; i++)
8531 {
8532 if (joy[joystick_index].stick[s].axis[i].d1 || joy[joystick_index].stick[s].axis[i].d2)
8533 return true;
8534 }
8535 return false;
8536 }
8537
8538 const char* joybtn_name(int32_t b)
8539 {
8540 if (b <= 0 || b > joy[joystick_index].num_buttons)
8541 return "";
8542
8543 return joy[joystick_index].button[b-1].name;
8544 }
8545
8546 const char* joystick_name(int32_t s)
8547 {
8548 if (s < 0 || s >= joy[joystick_index].num_sticks)
8549 return "";
8550
8551 return joy[joystick_index].stick[s].name;
8552 }
8553
8554 int32_t button_pressed()
8555 {
8556 if (joystick_index >= MAX_JOYSTICKS)
8557 return 0;
8558
8559 for(int32_t i=1; i<=joy[joystick_index].num_buttons; i++)
8560 {
8561 if(joybtn(i))
8562 return i;
8563 }
8564
8565 return 0;
8566 }
8567
8568 int32_t next_press_key();
8569
8570 int32_t next_joy_input(bool buttons)
8571 {
8572 clear_keybuf();
8573
8574 //first, we need to wait until they're pressing no buttons
8575 for(;;)
8576 {
8577 if(keypressed())
8578 {
8579 switch(readkey()>>8)
8580 {
8581 case KEY_ESC:
8582 return -1;
8583
8584 case KEY_SPACE:
8585 return 0;
8586 }
8587 }
8588
8589 poll_joystick();
8590 bool done = true;
8591
8592 if (buttons)
8593 {
8594 for(int32_t i=1; i<=joy[joystick_index].num_buttons; i++)
8595 {
8596 if(joybtn(i)) done = false;
8597 }
8598 }
8599 else
8600 {
8601 if (!gamepad_dlg_cur_joystick || !al_get_joystick_active(gamepad_dlg_cur_joystick))
8602 {
8603 InfoDialog("ZC", "Invalid gamepad. Did it disconnect?").show();
8604 return -2;
8605 }
8606 for(int32_t i=0; i<joy[joystick_index].num_sticks; i++)
8607 {
8608 if(joystick(i)) done = false;
8609 }
8610 }
8611
8612 if(done) break;
8613 rest(1);
8614 }
8615
8616 //now, we need to wait for them to press any button
8617 for(;;)
8618 {
8619 if(keypressed())
8620 {
8621 switch(readkey()>>8)
8622 {
8623 case KEY_ESC:
8624 return -1;
8625
8626 case KEY_SPACE:
8627 return 0;
8628 }
8629 }
8630
8631 poll_joystick();
8632
8633 if (buttons)
8634 {
8635 if (!gamepad_dlg_cur_joystick || !al_get_joystick_active(gamepad_dlg_cur_joystick))
8636 {
8637 InfoDialog("ZC", "Invalid gamepad. Did it disconnect?").show();
8638 return -2;
8639 }
8640 for(int32_t i=1; i<=joy[joystick_index].num_buttons; i++)
8641 {
8642 if(joybtn(i))
8643 return i;
8644 }
8645 }
8646 else
8647 {
8648 for(int32_t i=0; i<joy[joystick_index].num_sticks; i++)
8649 {
8650 if(joystick(i))
8651 return i;
8652 }
8653 }
8654 rest(1);
8655 }
8656 }
8657
8658 7771257 static bool rButton(bool &btn, bool &flag, bool rawbtn)
8659 {
8660
2/2
✓ Branch 0 taken 7743018 times.
✓ Branch 1 taken 28239 times.
7771257 bool ret = btn && !flag;
8661 7771257 flag = rawbtn;
8662
8663 7771257 return ret;
8664 }
8665 373256381 static bool rButton(bool &btn, bool &flag)
8666 {
8667
2/2
✓ Branch 0 taken 359480299 times.
✓ Branch 1 taken 13776082 times.
373256381 bool ret = btn && !flag;
8668 373256381 flag = btn;
8669
8670 373256381 return ret;
8671 }
8672 4521943 static bool rButtonPeek(bool btn, bool flag)
8673 {
8674
2/2
✓ Branch 0 taken 4188147 times.
✓ Branch 1 taken 333796 times.
4521943 if(!btn)
8675 {
8676 4188147 return false;
8677 }
8678
2/2
✓ Branch 0 taken 32175 times.
✓ Branch 1 taken 301621 times.
333796 else if(!flag)
8679 {
8680 32175 return true;
8681 }
8682
8683 301621 return false;
8684 4521943 }
8685
8686 // Updated only by keyboard/gamepad.
8687 // If in replay mode, this is set directly by the replay system.
8688 // This should never be read from directly - use control_state instead.
8689 bool raw_control_state[ZC_CONTROL_STATES];
8690
8691 // Every call to load_control_state (pretty much every frame) resets this to be equal to raw_control_state.
8692 // This state can drift from raw_control_state if button states are "eaten" or overriden by a script. But that only
8693 // lasts until the next call to load_control_state.
8694 bool control_state[ZC_CONTROL_STATES];
8695 bool disable_control[ZC_CONTROL_STATES];
8696 bool drunk_toggle_state[11];
8697 bool disabledKeys[127];
8698 bool KeyInput[127];
8699 bool KeyPress[127];
8700
8701 bool key_current_frame[127];
8702 bool key_previous_frame[127];
8703
8704 static bool key_system[127];
8705 static bool key_system_previous[127];
8706 static bool key_system_press[127];
8707
8708 bool button_press[ZC_CONTROL_STATES];
8709 bool button_hold[ZC_CONTROL_STATES];
8710
8711 #define STICK_1_X joy[joystick_index].stick[js_stick_1_x_stick].axis[js_stick_1_x_axis]
8712 #define STICK_1_Y joy[joystick_index].stick[js_stick_1_y_stick].axis[js_stick_1_y_axis]
8713 #define STICK_2_X joy[joystick_index].stick[js_stick_2_x_stick].axis[js_stick_2_x_axis]
8714 #define STICK_2_Y joy[joystick_index].stick[js_stick_2_y_stick].axis[js_stick_2_y_axis]
8715 #define STICK_PRECISION 56 //define your own sensitivity
8716
8717 15512787 void load_control_state()
8718 {
8719 15512787 load_control_called_this_frame = true;
8720
8721
2/2
✓ Branch 0 taken 12309725 times.
✓ Branch 1 taken 3203062 times.
15512787 if (replay_version_check(8, 11))
8722 {
8723
2/2
✓ Branch 0 taken 57655116 times.
✓ Branch 1 taken 3203062 times.
60858178 for (int i = 0; i < ZC_CONTROL_STATES; i++)
8724 57655116 down_control_states[i] = raw_control_state[i];
8725 3203062 }
8726
8727
2/2
✓ Branch 0 taken 15512766 times.
✓ Branch 1 taken 21 times.
15512787 if (!replay_is_replaying())
8728 {
8729
3/6
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
✓ Branch 2 taken 21 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 21 times.
✗ Branch 5 not taken.
21 raw_control_state[0]=zc_getrawkey(DUkey, true)||(analog_movement ? STICK_1_Y.d1 || STICK_1_Y.pos - js_stick_1_y_offset < -STICK_PRECISION : joybtn(DUbtn));
8730
3/6
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
✓ Branch 2 taken 21 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 21 times.
✗ Branch 5 not taken.
21 raw_control_state[1]=zc_getrawkey(DDkey, true)||(analog_movement ? STICK_1_Y.d2 || STICK_1_Y.pos - js_stick_1_y_offset > STICK_PRECISION : joybtn(DDbtn));
8731
3/6
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
✓ Branch 2 taken 21 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 21 times.
✗ Branch 5 not taken.
21 raw_control_state[2]=zc_getrawkey(DLkey, true)||(analog_movement ? STICK_1_X.d1 || STICK_1_X.pos - js_stick_1_x_offset < -STICK_PRECISION : joybtn(DLbtn));
8732
3/6
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
✓ Branch 2 taken 21 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 21 times.
✗ Branch 5 not taken.
21 raw_control_state[3]=zc_getrawkey(DRkey, true)||(analog_movement ? STICK_1_X.d2 || STICK_1_X.pos - js_stick_1_x_offset > STICK_PRECISION : joybtn(DRbtn));
8733
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[4]=zc_getrawkey(Akey, true)||joybtn(Abtn);
8734
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[5]=zc_getrawkey(Bkey, true)||joybtn(Bbtn);
8735
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[6]=zc_getrawkey(Skey, true)||joybtn(Sbtn);
8736
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[7]=zc_getrawkey(Lkey, true)||joybtn(Lbtn);
8737
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[8]=zc_getrawkey(Rkey, true)||joybtn(Rbtn);
8738
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[9]=zc_getrawkey(Pkey, true)||joybtn(Pbtn);
8739
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[10]=zc_getrawkey(Exkey1, true)||joybtn(Exbtn1);
8740
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[11]=zc_getrawkey(Exkey2, true)||joybtn(Exbtn2);
8741
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[12]=zc_getrawkey(Exkey3, true)||joybtn(Exbtn3);
8742
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[13]=zc_getrawkey(Exkey4, true)||joybtn(Exbtn4);
8743
8744
1/2
✓ Branch 0 taken 21 times.
✗ Branch 1 not taken.
21 if(num_joysticks != 0)
8745 {
8746 raw_control_state[14] = STICK_2_Y.pos - js_stick_2_y_offset < -STICK_PRECISION;
8747 raw_control_state[15] = STICK_2_Y.pos - js_stick_2_y_offset > STICK_PRECISION;
8748 raw_control_state[16] = STICK_2_X.pos - js_stick_2_x_offset < -STICK_PRECISION;
8749 raw_control_state[17] = STICK_2_X.pos - js_stick_2_x_offset > STICK_PRECISION;
8750 }
8751 else
8752 {
8753 21 raw_control_state[14] = false;
8754 21 raw_control_state[15] = false;
8755 21 raw_control_state[16] = false;
8756 21 raw_control_state[17] = false;
8757 }
8758 21 }
8759
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 15512782 times.
15512787 if (replay_is_active())
8760 {
8761
2/2
✓ Branch 0 taken 1211700 times.
✓ Branch 1 taken 14301082 times.
15512782 if (replay_get_version() < 3)
8762 1211700 replay_poll();
8763
4/4
✓ Branch 0 taken 14301061 times.
✓ Branch 1 taken 21 times.
✓ Branch 2 taken 12539686 times.
✓ Branch 3 taken 1761375 times.
14301082 else if (replay_is_replaying() && replay_get_version() < 6)
8764 1761375 replay_peek_input();
8765
4/4
✓ Branch 0 taken 12539686 times.
✓ Branch 1 taken 21 times.
✓ Branch 2 taken 9336624 times.
✓ Branch 3 taken 3203062 times.
12539707 else if (replay_is_replaying() && replay_version_check(8, 11))
8766 3203062 replay_peek_input();
8767
2/2
✓ Branch 0 taken 14172840 times.
✓ Branch 1 taken 1339942 times.
15512782 if (replay_get_version() == 8)
8768 1339942 update_keys();
8769 15512782 }
8770
8771 // Some test replay files were made before a serious input bug was fixed, so instead
8772 // of re-doing them or tossing them out, just check for that zplay version.
8773
3/4
✓ Branch 0 taken 15512777 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 121900 times.
✓ Branch 3 taken 15390877 times.
15512787 bool botched_input = replay_is_active() && replay_get_version() != 1 && replay_get_version() < 8;
8774
2/2
✓ Branch 0 taken 279229986 times.
✓ Branch 1 taken 15512777 times.
294742763 for (int i = 0; i < ZC_CONTROL_STATES; i++)
8775 {
8776 279229986 control_state[i] = raw_control_state[i];
8777
4/4
✓ Branch 0 taken 53024022 times.
✓ Branch 1 taken 226205964 times.
✓ Branch 2 taken 2611994 times.
✓ Branch 3 taken 50412028 times.
279229986 if (botched_input && !control_state[i])
8778 50412028 down_control_states[i] = false;
8779 279229986 }
8780 15512777 bool did_bad_cutscene_btn = false;
8781
2/2
✓ Branch 0 taken 15512777 times.
✓ Branch 1 taken 279229986 times.
294742763 for(int q = 0; q < 18; ++q)
8782
4/4
✓ Branch 0 taken 13205339 times.
✓ Branch 1 taken 266024647 times.
✓ Branch 2 taken 13203756 times.
✓ Branch 3 taken 1583 times.
279231569 if(control_state[q] && !active_cutscene.can_button(q))
8783 {
8784 1583 control_state[q] = false;
8785 1583 did_bad_cutscene_btn = true;
8786 1583 }
8787
2/2
✓ Branch 0 taken 15511632 times.
✓ Branch 1 taken 1145 times.
15512777 if(did_bad_cutscene_btn)
8788 1145 active_cutscene.error();
8789
8790 15512777 button_press[0]=rButton(control_state[0],button_hold[0]);
8791 15512777 button_press[1]=rButton(control_state[1],button_hold[1]);
8792 15512777 button_press[2]=rButton(control_state[2],button_hold[2]);
8793 15512777 button_press[3]=rButton(control_state[3],button_hold[3]);
8794 15512777 button_press[4]=rButton(control_state[4],button_hold[4]);
8795 15512777 button_press[5]=rButton(control_state[5],button_hold[5]);
8796 15512777 button_press[6]=rButton(control_state[6],button_hold[6]);
8797 15512777 button_press[7]=rButton(control_state[7],button_hold[7]);
8798 15512777 button_press[8]=rButton(control_state[8],button_hold[8]);
8799 15512777 button_press[9]=rButton(control_state[9],button_hold[9]);
8800 15512777 button_press[10]=rButton(control_state[10],button_hold[10]);
8801 15512777 button_press[11]=rButton(control_state[11],button_hold[11]);
8802 15512777 button_press[12]=rButton(control_state[12],button_hold[12]);
8803 15512777 button_press[13]=rButton(control_state[13],button_hold[13]);
8804 15512777 button_press[14]=rButton(control_state[14],button_hold[14]);
8805 15512777 button_press[15]=rButton(control_state[15],button_hold[15]);
8806 15512777 button_press[16]=rButton(control_state[16],button_hold[16]);
8807 15512777 button_press[17]=rButton(control_state[17],button_hold[17]);
8808 15512777 }
8809
8810 // Returns true if any game key is pressed. This is needed because keypressed()
8811 // doesn't detect modifier keys and control_state[] can be modified by scripts.
8812 78010434 bool zc_key_pressed()
8813 //may also need to use zc_getrawkey
8814 {
8815
7/10
✓ Branch 0 taken 63007466 times.
✓ Branch 1 taken 15002968 times.
✓ Branch 2 taken 15002968 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 15002968 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 12293395 times.
✓ Branch 7 taken 12293395 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 4916157 times.
82926591 if((zc_getrawkey(DUkey, true)||(analog_movement ? STICK_1_Y.d1 || STICK_1_Y.pos - js_stick_1_y_offset< -STICK_PRECISION : joybtn(DUbtn))) ||
8816
4/6
✓ Branch 0 taken 12293395 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12293395 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 9360722 times.
✓ Branch 5 taken 9360722 times.
12293395 (zc_getrawkey(DDkey, true)||(analog_movement ? STICK_1_Y.d2 || STICK_1_Y.pos - js_stick_1_y_offset > STICK_PRECISION : joybtn(DDbtn))) ||
8817
4/6
✓ Branch 0 taken 9360722 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9360722 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6197143 times.
✓ Branch 5 taken 6197143 times.
9360722 (zc_getrawkey(DLkey, true)||(analog_movement ? STICK_1_X.d1 || STICK_1_X.pos - js_stick_1_x_offset < -STICK_PRECISION : joybtn(DLbtn))) ||
8818
4/6
✓ Branch 0 taken 6197143 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6197143 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 5320948 times.
✓ Branch 5 taken 5320948 times.
6197143 (zc_getrawkey(DRkey, true)||(analog_movement ? STICK_1_X.d2 || STICK_1_X.pos - js_stick_1_x_offset > STICK_PRECISION : joybtn(DRbtn))) ||
8819
1/2
✓ Branch 0 taken 5320948 times.
✗ Branch 1 not taken.
5320948 (zc_getrawkey(Akey, true)||joybtn(Abtn)) ||
8820
3/4
✓ Branch 0 taken 5135863 times.
✓ Branch 1 taken 185085 times.
✓ Branch 2 taken 5135863 times.
✗ Branch 3 not taken.
5320948 (zc_getrawkey(Bkey, true)||joybtn(Bbtn)) ||
8821
3/4
✓ Branch 0 taken 4990537 times.
✓ Branch 1 taken 145326 times.
✓ Branch 2 taken 4990537 times.
✗ Branch 3 not taken.
5135863 (zc_getrawkey(Skey, true)||joybtn(Sbtn)) ||
8822
3/4
✓ Branch 0 taken 4968491 times.
✓ Branch 1 taken 22046 times.
✓ Branch 2 taken 4968491 times.
✗ Branch 3 not taken.
4990537 (zc_getrawkey(Lkey, true)||joybtn(Lbtn)) ||
8823
3/4
✓ Branch 0 taken 4942595 times.
✓ Branch 1 taken 25896 times.
✓ Branch 2 taken 4942595 times.
✗ Branch 3 not taken.
4968491 (zc_getrawkey(Rkey, true)||joybtn(Rbtn)) ||
8824
3/4
✓ Branch 0 taken 4935319 times.
✓ Branch 1 taken 7276 times.
✓ Branch 2 taken 4935319 times.
✗ Branch 3 not taken.
4942595 (zc_getrawkey(Pkey, true)||joybtn(Pbtn)) ||
8825
3/4
✓ Branch 0 taken 4918080 times.
✓ Branch 1 taken 17239 times.
✓ Branch 2 taken 4918080 times.
✗ Branch 3 not taken.
4935319 (zc_getrawkey(Exkey1, true)||joybtn(Exbtn1)) ||
8826
3/4
✓ Branch 0 taken 4916251 times.
✓ Branch 1 taken 1829 times.
✓ Branch 2 taken 4916251 times.
✗ Branch 3 not taken.
4918080 (zc_getrawkey(Exkey2, true)||joybtn(Exbtn2)) ||
8827
3/4
✓ Branch 0 taken 4916216 times.
✓ Branch 1 taken 35 times.
✓ Branch 2 taken 4916216 times.
✗ Branch 3 not taken.
4916251 (zc_getrawkey(Exkey3, true)||joybtn(Exbtn3)) ||
8828
2/2
✓ Branch 0 taken 4916157 times.
✓ Branch 1 taken 59 times.
4916216 (zc_getrawkey(Exkey4, true)||joybtn(Exbtn4))) // Skipping joystick axes
8829 139438693 return true;
8830
8831 4916157 return false;
8832 18339918 }
8833
8834 294881078 bool getInput(int32_t btn, bool press, bool drunk, bool ignoreDisable, bool eatEntirely, bool peek)
8835 {
8836 294881078 bool ret = false, drunkstate = false, rawret = false;;
8837 294881078 bool* flag = &down_control_states[btn];
8838
2/7
✓ Branch 0 taken 276522516 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 18358562 times.
294881078 switch(btn)
8839 {
8840 case btnF12:
8841 ret = zc_getkey(KEY_F12, ignoreDisable);
8842 rawret = zc_getrawkey(KEY_F12, ignoreDisable);
8843 eatEntirely = false;
8844 break;
8845 case btnF11:
8846 ret = zc_getkey(KEY_F11, ignoreDisable);
8847 rawret = zc_getrawkey(KEY_F11, ignoreDisable);
8848 eatEntirely = false;
8849 break;
8850 case btnF5:
8851 ret = zc_getkey(KEY_F5, ignoreDisable);
8852 rawret = zc_getrawkey(KEY_F5, ignoreDisable);
8853 eatEntirely = false;
8854 break;
8855 case btnQ:
8856 ret = zc_getkey(KEY_Q, ignoreDisable);
8857 rawret = zc_getrawkey(KEY_Q, ignoreDisable);
8858 eatEntirely = false;
8859 break;
8860 case btnI:
8861 ret = zc_getkey(KEY_I, ignoreDisable);
8862 rawret = zc_getrawkey(KEY_I, ignoreDisable);
8863 eatEntirely = false;
8864 break;
8865 case btnM:
8866
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18358562 times.
18358562 if(FFCore.kb_typing_mode) return false;
8867 18358562 rawret = ret = zc_getrawkey(KEY_ESC, ignoreDisable);
8868 18358562 eatEntirely = false;
8869 18358562 break;
8870 default: //control_state[] index
8871
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 276522516 times.
276522516 if(FFCore.kb_typing_mode) return false;
8872
6/6
✓ Branch 0 taken 275147343 times.
✓ Branch 1 taken 1375173 times.
✓ Branch 2 taken 17801617 times.
✓ Branch 3 taken 257345726 times.
✓ Branch 4 taken 17798644 times.
✓ Branch 5 taken 2973 times.
276522516 if(!ignoreDisable && get_qr(qr_FIXDRUNKINPUTS) && disable_control[btn]) drunk = false;
8873
2/2
✓ Branch 0 taken 15777099 times.
✓ Branch 1 taken 260742444 times.
276519543 else if(btn<11) drunkstate = drunk_toggle_state[btn];
8874
4/4
✓ Branch 0 taken 245654061 times.
✓ Branch 1 taken 30868455 times.
✓ Branch 2 taken 7103 times.
✓ Branch 3 taken 30861352 times.
307390971 ret = control_state[btn] && (ignoreDisable || !disable_control[btn]);
8875 276522516 rawret = raw_control_state[btn];
8876 276522516 }
8877
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 294881078 times.
294881078 assert(flag);
8878
2/2
✓ Branch 0 taken 188561483 times.
✓ Branch 1 taken 106319595 times.
294881078 if(press)
8879 {
8880
2/2
✓ Branch 0 taken 4521943 times.
✓ Branch 1 taken 101797652 times.
106319595 if(peek)
8881 4521943 ret = rButtonPeek(ret, *flag);
8882
2/2
✓ Branch 0 taken 94026395 times.
✓ Branch 1 taken 7771257 times.
101797652 else if(get_qr(qr_BROKEN_INPUT_DOWN_STATE)) ret = rButton(ret, *flag);
8883 7771257 else ret = rButton(ret, *flag, rawret);
8884 106319595 }
8885
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 294881078 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
294881078 if(eatEntirely && ret) control_state[btn] = false;
8886
4/4
✓ Branch 0 taken 220148524 times.
✓ Branch 1 taken 74732554 times.
✓ Branch 2 taken 220148443 times.
✓ Branch 3 taken 81 times.
294881078 if(drunk && drunkstate) ret = !ret;
8887 294881078 return ret;
8888 294881078 }
8889
8890 14907549 byte getIntBtnInput(byte intbtn, bool press, bool drunk, bool ignoreDisable, bool eatEntirely, bool peek)
8891 {
8892 14907549 byte ret = 0;
8893
2/2
✓ Branch 0 taken 10609297 times.
✓ Branch 1 taken 4298252 times.
14907549 if(intbtn & INT_BTN_A) ret |= getInput(btnA, press, drunk, ignoreDisable, eatEntirely, peek) ? INT_BTN_A : 0;
8894
2/2
✓ Branch 0 taken 14699850 times.
✓ Branch 1 taken 207699 times.
14907549 if(intbtn & INT_BTN_B) ret |= getInput(btnB, press, drunk, ignoreDisable, eatEntirely, peek) ? INT_BTN_B : 0;
8895
2/2
✓ Branch 0 taken 14701168 times.
✓ Branch 1 taken 206381 times.
14907549 if(intbtn & INT_BTN_L) ret |= getInput(btnL, press, drunk, ignoreDisable, eatEntirely, peek) ? INT_BTN_L : 0;
8896
2/2
✓ Branch 0 taken 14701168 times.
✓ Branch 1 taken 206381 times.
14907549 if(intbtn & INT_BTN_R) ret |= getInput(btnR, press, drunk, ignoreDisable, eatEntirely, peek) ? INT_BTN_R : 0;
8897
2/2
✓ Branch 0 taken 14701168 times.
✓ Branch 1 taken 206381 times.
14907549 if(intbtn & INT_BTN_EX1) ret |= getInput(btnEx1, press, drunk, ignoreDisable, eatEntirely, peek) ? INT_BTN_EX1 : 0;
8898
2/2
✓ Branch 0 taken 14701168 times.
✓ Branch 1 taken 206381 times.
14907549 if(intbtn & INT_BTN_EX2) ret |= getInput(btnEx2, press, drunk, ignoreDisable, eatEntirely, peek) ? INT_BTN_EX2 : 0;
8899
2/2
✓ Branch 0 taken 14701168 times.
✓ Branch 1 taken 206381 times.
14907549 if(intbtn & INT_BTN_EX3) ret |= getInput(btnEx3, press, drunk, ignoreDisable, eatEntirely, peek) ? INT_BTN_EX3 : 0;
8900
2/2
✓ Branch 0 taken 14701053 times.
✓ Branch 1 taken 206496 times.
14907549 if(intbtn & INT_BTN_EX4) ret |= getInput(btnEx4, press, drunk, ignoreDisable, eatEntirely, peek) ? INT_BTN_EX4 : 0;
8901 14907549 return ret; //No early return, to make sure all button presses are eaten that should be! -Em
8902 }
8903
8904 7362 byte checkIntBtnVal(byte intbtn, byte vals)
8905 {
8906 7362 return intbtn&vals;
8907 }
8908
8909 3727949 bool Up()
8910 {
8911 3727949 return getInput(btnUp);
8912 }
8913 740027 bool Down()
8914 {
8915 740027 return getInput(btnDown);
8916 }
8917 1007972 bool Left()
8918 {
8919 1007972 return getInput(btnLeft);
8920 }
8921 1075801 bool Right()
8922 {
8923 1075801 return getInput(btnRight);
8924 }
8925 526336 bool cAbtn()
8926 {
8927 526336 return getInput(btnA);
8928 }
8929 3232586 bool cBbtn()
8930 {
8931 3232586 return getInput(btnB);
8932 }
8933 bool cSbtn()
8934 {
8935 return getInput(btnS);
8936 }
8937 208608 bool cLbtn()
8938 {
8939 208608 return getInput(btnL);
8940 }
8941 208608 bool cRbtn()
8942 {
8943 208608 return getInput(btnR);
8944 }
8945 bool cPbtn()
8946 {
8947 return getInput(btnP);
8948 }
8949 bool cEx1btn()
8950 {
8951 return getInput(btnEx1);
8952 }
8953 bool cEx2btn()
8954 {
8955 return getInput(btnEx2);
8956 }
8957 bool cEx3btn()
8958 {
8959 return getInput(btnEx3);
8960 }
8961 bool cEx4btn()
8962 {
8963 return getInput(btnEx4);
8964 }
8965 bool AxisUp()
8966 {
8967 return getInput(btnAxisUp);
8968 }
8969 bool AxisDown()
8970 {
8971 return getInput(btnAxisDown);
8972 }
8973 bool AxisLeft()
8974 {
8975 return getInput(btnAxisLeft);
8976 }
8977 bool AxisRight()
8978 {
8979 return getInput(btnAxisRight);
8980 }
8981
8982 bool cMbtn()
8983 {
8984 return getInput(btnM);
8985 }
8986 bool cF12()
8987 {
8988 return getInput(btnF12);
8989 }
8990 bool cF11()
8991 {
8992 return getInput(btnF11);
8993 }
8994 bool cF5()
8995 {
8996 return getInput(btnF5);
8997 }
8998 bool cQ()
8999 {
9000 return getInput(btnQ);
9001 }
9002 bool cI()
9003 {
9004 return getInput(btnI);
9005 }
9006
9007 210045 bool rUp()
9008 {
9009 210045 return getInput(btnUp, true);
9010 }
9011 209832 bool rDown()
9012 {
9013 209832 return getInput(btnDown, true);
9014 }
9015 209638 bool rLeft()
9016 {
9017 209638 return getInput(btnLeft, true);
9018 }
9019 208903 bool rRight()
9020 {
9021 208903 return getInput(btnRight, true);
9022 }
9023 7045 bool rAbtn()
9024 {
9025 7045 return getInput(btnA, true);
9026 }
9027 2397 bool rBbtn()
9028 {
9029 2397 return getInput(btnB, true);
9030 }
9031 14370752 bool rSbtn()
9032 {
9033 14370752 return getInput(btnS, true);
9034 }
9035 18339918 bool rMbtn()
9036 {
9037 18339918 return getInput(btnM, true);
9038 }
9039 184787 bool rLbtn()
9040 {
9041 184787 return getInput(btnL, true);
9042 }
9043 184782 bool rRbtn()
9044 {
9045 184782 return getInput(btnR, true);
9046 }
9047 14371890 bool rPbtn()
9048 {
9049 14371890 return getInput(btnP, true);
9050 }
9051 bool rEx1btn()
9052 {
9053 return getInput(btnEx1, true);
9054 }
9055 bool rEx2btn()
9056 {
9057 return getInput(btnEx2, true);
9058 }
9059 195433 bool rEx3btn()
9060 {
9061 195433 return getInput(btnEx3, true);
9062 }
9063 195433 bool rEx4btn()
9064 {
9065 195433 return getInput(btnEx4, true);
9066 }
9067 bool rAxisUp()
9068 {
9069 return getInput(btnAxisUp, true);
9070 }
9071 bool rAxisDown()
9072 {
9073 return getInput(btnAxisDown, true);
9074 }
9075 bool rAxisLeft()
9076 {
9077 return getInput(btnAxisLeft, true);
9078 }
9079 bool rAxisRight()
9080 {
9081 return getInput(btnAxisRight, true);
9082 }
9083
9084 bool rF11()
9085 {
9086 return getInput(btnF11, true);
9087 }
9088 bool rQ()
9089 {
9090 return getInput(btnQ, true);
9091 }
9092 bool rI()
9093 {
9094 return getInput(btnI, true);
9095 }
9096
9097 36654130 bool DrunkUp()
9098 {
9099 36654130 return getInput(btnUp, false, true);
9100 }
9101 33450620 bool DrunkDown()
9102 {
9103 33450620 return getInput(btnDown, false, true);
9104 }
9105 19547268 bool DrunkLeft()
9106 {
9107 19547268 return getInput(btnLeft, false, true);
9108 }
9109 16607509 bool DrunkRight()
9110 {
9111 16607509 return getInput(btnRight, false, true);
9112 }
9113 15763999 bool DrunkcAbtn()
9114 {
9115 15763999 return getInput(btnA, false, true);
9116 }
9117 15215201 bool DrunkcBbtn()
9118 {
9119 15215201 return getInput(btnB, false, true);
9120 }
9121 14163097 bool DrunkcEx1btn()
9122 {
9123 14163097 return getInput(btnEx1, false, true);
9124 }
9125 14161729 bool DrunkcEx2btn()
9126 {
9127 14161729 return getInput(btnEx2, false, true);
9128 }
9129 bool DrunkcSbtn()
9130 {
9131 return getInput(btnS, false, true);
9132 }
9133 bool DrunkcMbtn()
9134 {
9135 return getInput(btnM, false, true);
9136 }
9137 bool DrunkcLbtn()
9138 {
9139 return getInput(btnL, false, true);
9140 }
9141 bool DrunkcRbtn()
9142 {
9143 return getInput(btnR, false, true);
9144 }
9145 bool DrunkcPbtn()
9146 {
9147 return getInput(btnP, false, true);
9148 }
9149
9150 bool DrunkrUp()
9151 {
9152 return getInput(btnUp, true, true);
9153 }
9154 bool DrunkrDown()
9155 {
9156 return getInput(btnDown, true, true);
9157 }
9158 bool DrunkrLeft()
9159 {
9160 return getInput(btnLeft, true, true);
9161 }
9162 bool DrunkrRight()
9163 {
9164 return getInput(btnRight, true, true);
9165 }
9166 11859194 bool DrunkrAbtn()
9167 {
9168 11859194 return getInput(btnA, true, true);
9169 }
9170 11887652 bool DrunkrBbtn()
9171 {
9172 11887652 return getInput(btnB, true, true);
9173 }
9174 549513 bool DrunkrEx1btn()
9175 {
9176 549513 return getInput(btnEx1, true, true);
9177 }
9178 549314 bool DrunkrEx2btn()
9179 {
9180 549314 return getInput(btnEx2, true, true);
9181 }
9182 bool DrunkrEx3btn()
9183 {
9184 return getInput(btnEx3, true, true);
9185 }
9186 bool DrunkrEx4btn()
9187 {
9188 return getInput(btnEx4, true, true);
9189 }
9190 bool DrunkrSbtn()
9191 {
9192 return getInput(btnS, true, true);
9193 }
9194 bool DrunkrMbtn()
9195 {
9196 return getInput(btnM, true, true);
9197 }
9198 12825090 bool DrunkrLbtn()
9199 {
9200 12825090 return getInput(btnL, true, true);
9201 }
9202 12819808 bool DrunkrRbtn()
9203 {
9204 12819808 return getInput(btnR, true, true);
9205 }
9206 bool DrunkrPbtn()
9207 {
9208 return getInput(btnP, true, true);
9209 }
9210
9211 18644 void eat_buttons()
9212 {
9213 18644 getInput(btnA, true, false, true);
9214 18644 getInput(btnB, true, false, true);
9215 18644 getInput(btnS, true, false, true);
9216 18644 getInput(btnM, true, false, true);
9217 18644 getInput(btnL, true, false, true);
9218 18644 getInput(btnR, true, false, true);
9219 18644 getInput(btnP, true, false, true);
9220 18644 getInput(btnEx1, true, false, true);
9221 18644 getInput(btnEx2, true, false, true);
9222 18644 getInput(btnEx3, true, false, true);
9223 18644 getInput(btnEx4, true, false, true);
9224 18644 }
9225
9226 // Is true for the _first frame_ of a key press.
9227 // But! it is possible that a script manually sets the value of KeyPress,
9228 // in which case it will be restored to the "true" value based on `key_current_frame`
9229 // and `key_previous_frame` on the next frame.
9230 45 bool zc_readkey(int32_t k, bool ignoreDisable)
9231 {
9232
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 45 times.
45 if(ignoreDisable) return KeyPress[k];
9233
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 45 times.
45 switch(k)
9234 {
9235 case KEY_F7:
9236 case KEY_F8:
9237 case KEY_F9:
9238 return KeyPress[k];
9239
9240 default:
9241
1/2
✓ Branch 0 taken 45 times.
✗ Branch 1 not taken.
45 return KeyPress[k] && !disabledKeys[k];
9242 }
9243 45 }
9244
9245 // Is true for _every frame_ a key is held down.
9246 // But! it is possible that a script manually sets the value of KeyInput,
9247 // in which case it will be restored to the "true" value based on `key_current_frame`
9248 // on the next frame.
9249 bool zc_getkey(int32_t k, bool ignoreDisable)
9250 {
9251 if(ignoreDisable) return KeyInput[k];
9252 switch(k)
9253 {
9254 case KEY_F7:
9255 case KEY_F8:
9256 case KEY_F9:
9257 return KeyInput[k];
9258
9259 default:
9260 return KeyInput[k] && !disabledKeys[k];
9261 }
9262 }
9263
9264 // Reads (and then clears) the current frame key state directly.
9265 // Scripts can also modify `key_current_frame`.
9266 882 bool zc_readrawkey(int32_t k, bool ignoreDisable)
9267 {
9268
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 880 times.
882 if(zc_getrawkey(k, ignoreDisable))
9269 {
9270 2 _key[k]=key[k]=key_current_frame[k]=0;
9271 2 return true;
9272 }
9273 880 _key[k]=key[k]=key_current_frame[k]=0;
9274 880 return false;
9275 882 }
9276
9277 // Reads the current frame key state directly.
9278 // Scripts can also modify `key_current_frame`.
9279 124598184 bool zc_getrawkey(int32_t k, bool ignoreDisable)
9280 {
9281
2/2
✓ Branch 0 taken 106258176 times.
✓ Branch 1 taken 18340008 times.
124598184 if(ignoreDisable) return key_current_frame[k];
9282
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18340008 times.
18340008 switch(k)
9283 {
9284 case KEY_F7:
9285 case KEY_F8:
9286 case KEY_F9:
9287 return key_current_frame[k];
9288
9289 default:
9290
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18340008 times.
18340008 return key_current_frame[k] && !disabledKeys[k];
9291 }
9292 124598184 }
9293
9294 // Only used for a handful of keys, like tilde and Function keys.
9295 // This state is never read within the game.
9296 // It exists so that all keyboard input still functions during replay,
9297 // without inadvertently doing things like toggling throttling if the player
9298 // presses ~
9299 bool zc_get_system_key(int32_t k)
9300 {
9301 return key_system[k];
9302 }
9303
9304 // True for the _first_ frame of a key press.
9305 165059262 bool zc_read_system_key(int32_t k)
9306 {
9307 165059262 return key_system_press[k];
9308 }
9309
9310 2329169586 bool is_system_key(int32_t k)
9311 {
9312
2/2
✓ Branch 0 taken 2164110324 times.
✓ Branch 1 taken 165059262 times.
2329169586 switch (k)
9313 {
9314 case KEY_BACKQUOTE:
9315 case KEY_CLOSEBRACE:
9316 case KEY_END:
9317 case KEY_HOME:
9318 case KEY_OPENBRACE:
9319 case KEY_PGDN:
9320 case KEY_PGUP:
9321 case KEY_TAB:
9322 case KEY_TILDE:
9323 165059262 return true;
9324 }
9325 2164110324 return is_Fkey(k);
9326 2329169586 }
9327
9328 18339918 void update_system_keys()
9329 {
9330
2/2
✓ Branch 0 taken 2329169586 times.
✓ Branch 1 taken 18339918 times.
2347509504 for (int32_t q = 0; q < 127; ++q)
9331 {
9332
2/2
✓ Branch 0 taken 385138278 times.
✓ Branch 1 taken 1944031308 times.
2329169586 if (!is_system_key(q))
9333 1944031308 continue;
9334
9335 385138278 key_system[q] = key[q];
9336
1/2
✓ Branch 0 taken 385138278 times.
✗ Branch 1 not taken.
385138278 key_system_press[q] = key_system[q] && !key_system_previous[q];
9337 385138278 key_system_previous[q] = key_system[q];
9338 385138278 }
9339 18339918 }
9340
9341 19679860 void update_keys()
9342 {
9343
2/2
✓ Branch 0 taken 2499342220 times.
✓ Branch 1 taken 19679860 times.
2519022080 for (int32_t q = 0; q < 127; ++q)
9344 {
9345 // When replaying, replay.cpp takes care of updating `key_current_frame`.
9346
2/2
✓ Branch 0 taken 2499329520 times.
✓ Branch 1 taken 12700 times.
2499342220 if (!replay_is_replaying())
9347 12700 key_current_frame[q] = key[q];
9348
9349
2/2
✓ Branch 0 taken 2480120265 times.
✓ Branch 1 taken 19221955 times.
2499342220 KeyPress[q] = key_current_frame[q] && !key_previous_frame[q];
9350 2499342220 KeyInput[q] = key_current_frame[q];
9351 2499342220 key_previous_frame[q] = key_current_frame[q];
9352 2499342220 }
9353 19679860 }
9354
9355